integral_c.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file integral_c.hpp
  3. /// Contains definition of the integral_c transform and friends.
  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. #ifndef BOOST_PROTO_TRANSFORM_INTEGRAL_C_HPP_EAN_04_28_2011
  9. #define BOOST_PROTO_TRANSFORM_INTEGRAL_C_HPP_EAN_04_28_2011
  10. #include <boost/proto/proto_fwd.hpp>
  11. #include <boost/proto/transform/impl.hpp>
  12. namespace boost { namespace proto
  13. {
  14. /// \brief A PrimitiveTransform that returns a specified
  15. /// integral constant
  16. ///
  17. template<typename T, T I>
  18. struct integral_c : transform<integral_c<T, I> >
  19. {
  20. template<typename Expr, typename State, typename Data>
  21. struct impl : transform_impl<Expr, State, Data>
  22. {
  23. typedef T result_type;
  24. /// \return \c I
  25. /// \throw nothrow
  26. T operator()(
  27. typename impl::expr_param
  28. , typename impl::state_param
  29. , typename impl::data_param
  30. ) const
  31. {
  32. return I;
  33. }
  34. };
  35. };
  36. /// \brief A PrimitiveTransform that returns a specified
  37. /// char
  38. ///
  39. template<char I>
  40. struct char_
  41. : integral_c<char, I>
  42. {};
  43. /// \brief A PrimitiveTransform that returns a specified
  44. /// int
  45. ///
  46. template<int I>
  47. struct int_
  48. : integral_c<int, I>
  49. {};
  50. /// \brief A PrimitiveTransform that returns a specified
  51. /// long
  52. ///
  53. template<long I>
  54. struct long_
  55. : integral_c<long, I>
  56. {};
  57. /// \brief A PrimitiveTransform that returns a specified
  58. /// std::size_t
  59. ///
  60. template<std::size_t I>
  61. struct size_t
  62. : integral_c<std::size_t, I>
  63. {};
  64. /// INTERNAL ONLY
  65. ///
  66. template<typename T, T I>
  67. struct is_callable<integral_c<T, I> >
  68. : mpl::true_
  69. {};
  70. /// INTERNAL ONLY
  71. ///
  72. template<char I>
  73. struct is_callable<char_<I> >
  74. : mpl::true_
  75. {};
  76. /// INTERNAL ONLY
  77. ///
  78. template<int I>
  79. struct is_callable<int_<I> >
  80. : mpl::true_
  81. {};
  82. /// INTERNAL ONLY
  83. ///
  84. template<long I>
  85. struct is_callable<long_<I> >
  86. : mpl::true_
  87. {};
  88. /// INTERNAL ONLY
  89. ///
  90. template<std::size_t I>
  91. struct is_callable<size_t<I> >
  92. : mpl::true_
  93. {};
  94. }}
  95. #endif