binding.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright David Abrahams 2005. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_PARAMETER_BINDING_DWA200558_HPP
  5. # define BOOST_PARAMETER_BINDING_DWA200558_HPP
  6. # include <boost/mpl/apply.hpp>
  7. # include <boost/mpl/assert.hpp>
  8. # include <boost/mpl/and.hpp>
  9. # include <boost/parameter/aux_/result_of0.hpp>
  10. # include <boost/parameter/aux_/void.hpp>
  11. # include <boost/type_traits/is_same.hpp>
  12. # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  13. # include <boost/mpl/eval_if.hpp>
  14. # endif
  15. namespace boost { namespace parameter {
  16. // A metafunction that, given an argument pack, returns the type of
  17. // the parameter identified by the given keyword. If no such
  18. // parameter has been specified, returns Default
  19. # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
  20. || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  21. template <class Parameters, class Keyword, class Default>
  22. struct binding0
  23. {
  24. typedef typename mpl::apply_wrap3<
  25. typename Parameters::binding,Keyword,Default,mpl::true_
  26. >::type type;
  27. BOOST_MPL_ASSERT_NOT((
  28. mpl::and_<
  29. is_same<Default, void_>
  30. , is_same<type, void_>
  31. >
  32. ));
  33. };
  34. # endif
  35. template <class Parameters, class Keyword, class Default = void_>
  36. # if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  37. struct binding
  38. # else
  39. struct binding_eti
  40. # endif
  41. {
  42. # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
  43. || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  44. typedef typename mpl::eval_if<
  45. mpl::is_placeholder<Parameters>
  46. , mpl::identity<int>
  47. , binding0<Parameters,Keyword,Default>
  48. >::type type;
  49. # else
  50. typedef typename mpl::apply_wrap3<
  51. typename Parameters::binding,Keyword,Default,mpl::true_
  52. >::type type;
  53. BOOST_MPL_ASSERT_NOT((
  54. mpl::and_<
  55. is_same<Default, void_>
  56. , is_same<type, void_>
  57. >
  58. ));
  59. # endif
  60. # if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  61. BOOST_MPL_AUX_LAMBDA_SUPPORT(3,binding,(Parameters,Keyword,Default))
  62. # endif
  63. };
  64. # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  65. template <class Parameters, class Keyword, class Default = void_>
  66. struct binding
  67. {
  68. typedef typename mpl::eval_if<
  69. is_same<Parameters, int>
  70. , mpl::identity<int>
  71. , binding_eti<Parameters, Keyword, Default>
  72. >::type type;
  73. BOOST_MPL_AUX_LAMBDA_SUPPORT(3,binding,(Parameters,Keyword,Default))
  74. };
  75. # endif
  76. // A metafunction that, given an argument pack, returns the type of
  77. // the parameter identified by the given keyword. If no such
  78. // parameter has been specified, returns the type returned by invoking
  79. // DefaultFn
  80. template <class Parameters, class Keyword, class DefaultFn>
  81. struct lazy_binding
  82. {
  83. typedef typename mpl::apply_wrap3<
  84. typename Parameters::binding
  85. , Keyword
  86. , typename aux::result_of0<DefaultFn>::type
  87. , mpl::true_
  88. >::type type;
  89. };
  90. }} // namespace boost::parameter
  91. #endif // BOOST_PARAMETER_BINDING_DWA200558_HPP