arity_code.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // -- Boost Lambda Library -------------------------------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see www.boost.org
  9. // --------------------------------------------------
  10. #ifndef BOOST_LAMBDA_ARITY_CODE_HPP
  11. #define BOOST_LAMBDA_ARITY_CODE_HPP
  12. #include "boost/type_traits/cv_traits.hpp"
  13. #include "boost/type_traits/transform_traits.hpp"
  14. namespace boost {
  15. namespace lambda {
  16. // These constants state, whether a lambda_functor instantiation results from
  17. // an expression which contains no placeholders (NONE),
  18. // only free1 placeholders (FIRST),
  19. // free2 placeholders and maybe free1 placeholders (SECOND),
  20. // free3 and maybe free1 and free2 placeholders (THIRD),
  21. // freeE placeholders and maybe free1 and free2 (EXCEPTION).
  22. // RETHROW means, that a rethrow expression is used somewhere in the lambda_functor.
  23. enum { NONE = 0x00, // Notice we are using bits as flags here.
  24. FIRST = 0x01,
  25. SECOND = 0x02,
  26. THIRD = 0x04,
  27. EXCEPTION = 0x08,
  28. RETHROW = 0x10};
  29. template<class T>
  30. struct get_tuple_arity;
  31. namespace detail {
  32. template <class T> struct get_arity_;
  33. } // end detail;
  34. template <class T> struct get_arity {
  35. BOOST_STATIC_CONSTANT(int, value = detail::get_arity_<typename boost::remove_cv<typename boost::remove_reference<T>::type>::type>::value);
  36. };
  37. namespace detail {
  38. template<class T>
  39. struct get_arity_ {
  40. BOOST_STATIC_CONSTANT(int, value = 0);
  41. };
  42. template<class T>
  43. struct get_arity_<lambda_functor<T> > {
  44. BOOST_STATIC_CONSTANT(int, value = get_arity<T>::value);
  45. };
  46. template<class Action, class Args>
  47. struct get_arity_<lambda_functor_base<Action, Args> > {
  48. BOOST_STATIC_CONSTANT(int, value = get_tuple_arity<Args>::value);
  49. };
  50. template<int I>
  51. struct get_arity_<placeholder<I> > {
  52. BOOST_STATIC_CONSTANT(int, value = I);
  53. };
  54. } // detail
  55. template<class T>
  56. struct get_tuple_arity {
  57. BOOST_STATIC_CONSTANT(int, value = get_arity<typename T::head_type>::value | get_tuple_arity<typename T::tail_type>::value);
  58. };
  59. template<>
  60. struct get_tuple_arity<null_type> {
  61. BOOST_STATIC_CONSTANT(int, value = 0);
  62. };
  63. // Does T have placeholder<I> as it's subexpression?
  64. template<class T, int I>
  65. struct has_placeholder {
  66. BOOST_STATIC_CONSTANT(bool, value = (get_arity<T>::value & I) != 0);
  67. };
  68. template<int I, int J>
  69. struct includes_placeholder {
  70. BOOST_STATIC_CONSTANT(bool, value = (J & I) != 0);
  71. };
  72. template<int I, int J>
  73. struct lacks_placeholder {
  74. BOOST_STATIC_CONSTANT(bool, value = ((J & I) == 0));
  75. };
  76. } // namespace lambda
  77. } // namespace boost
  78. #endif