template_arity.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file template_arity.hpp
  3. /// Replace all nodes stored by reference by nodes stored by value.
  4. //
  5. // Copyright 2011 Eric Niebler. Distributed under the Boost
  6. // Software License, Version 1.0. (See accompanying file
  7. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // This file is based on a similar one in MPL from Aleksey Gurtovoy.
  10. #ifndef BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07
  11. #define BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07
  12. // Somewhat indirect definition of BOOST_PROTO_TEMPLATE_ARITY_PARAM is
  13. // to overcome a shortcoming of the Wave tool used to generate the
  14. // pre-preprocessed headers.
  15. #define BOOST_PROTO_TEMPLATE_ARITY_PARAM BOOST_PROTO_TEMPLATE_ARITY_PARAM2
  16. #define BOOST_PROTO_TEMPLATE_ARITY_PARAM2(param)
  17. #if defined(BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING) || \
  18. (defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES))
  19. #include <boost/preprocessor/cat.hpp>
  20. #include <boost/preprocessor/inc.hpp>
  21. #include <boost/preprocessor/iteration/iterate.hpp>
  22. #include <boost/preprocessor/repetition/enum_params.hpp>
  23. #include <boost/mpl/int.hpp>
  24. #include <boost/proto/proto_fwd.hpp>
  25. #undef BOOST_PROTO_TEMPLATE_ARITY_PARAM2
  26. #define BOOST_PROTO_TEMPLATE_ARITY_PARAM2(param) , param
  27. namespace boost { namespace proto { namespace detail
  28. {
  29. sized_type<1>::type template_arity_helper(...);
  30. // Other overloads generated by the preprocessor
  31. #include <boost/proto/detail/template_arity_helper.hpp>
  32. template<typename F, int N, int Size>
  33. struct template_arity_impl2
  34. : mpl::int_<Size - 1>
  35. {};
  36. template<typename F, int N = BOOST_PROTO_MAX_ARITY>
  37. struct template_arity
  38. : template_arity_impl2<
  39. F
  40. , N
  41. , sizeof(detail::template_arity_helper((F **)0, (mpl::int_<N> *)0))
  42. >
  43. {};
  44. template<typename F, int N>
  45. struct template_arity_impl2<F, N, 1>
  46. : template_arity<F, N-1>
  47. {};
  48. template<typename F>
  49. struct template_arity_impl2<F, 0, 1>
  50. : mpl::int_<-1>
  51. {};
  52. }}}
  53. #endif // BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING
  54. #endif // BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07