default.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright Daniel Wallin, David Abrahams 2005.
  2. // Copyright Cromwell D. Enage 2017.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef DEFAULT_050329_HPP
  7. #define DEFAULT_050329_HPP
  8. namespace boost { namespace parameter { namespace aux {
  9. // A wrapper for the default value passed by the user when resolving
  10. // the value of the parameter with the given Keyword
  11. template <typename Keyword, typename Value>
  12. struct default_
  13. {
  14. inline BOOST_CONSTEXPR default_(Value& x) : value(x)
  15. {
  16. }
  17. Value& value;
  18. };
  19. }}} // namespace boost::parameter::aux
  20. #include <boost/parameter/config.hpp>
  21. namespace boost { namespace parameter { namespace aux {
  22. // lazy_default -- A wrapper for the default value computation function
  23. // passed by the user when resolving the value of the parameter with the
  24. // given keyword.
  25. #if BOOST_WORKAROUND(__EDG_VERSION__, <= 300)
  26. // These compilers need a little extra help with overload resolution;
  27. // we have empty_arg_list's operator[] accept a base class
  28. // to make that overload less preferable.
  29. template <typename KW, typename DefaultComputer>
  30. struct lazy_default_base
  31. {
  32. inline BOOST_CONSTEXPR lazy_default_base(DefaultComputer& x)
  33. : compute_default(x)
  34. {
  35. }
  36. DefaultComputer& compute_default;
  37. };
  38. template <typename KW, typename DefaultComputer>
  39. struct lazy_default
  40. : ::boost::parameter::aux::lazy_default_base<KW,DefaultComputer>
  41. {
  42. inline BOOST_CONSTEXPR lazy_default(DefaultComputer& x)
  43. : ::boost::parameter::aux::lazy_default_base<KW,DefaultComputer>(x)
  44. {
  45. }
  46. };
  47. #else // !BOOST_WORKAROUND(__EDG_VERSION__, <= 300)
  48. template <typename KW, typename DefaultComputer>
  49. struct lazy_default
  50. {
  51. inline BOOST_CONSTEXPR lazy_default(DefaultComputer& x)
  52. : compute_default(x)
  53. {
  54. }
  55. DefaultComputer& compute_default;
  56. };
  57. #endif // EDG workarounds needed.
  58. }}} // namespace boost::parameter::aux
  59. #if BOOST_WORKAROUND(__EDG_VERSION__, <= 300)
  60. #define BOOST_PARAMETER_lazy_default_fallback \
  61. ::boost::parameter::aux::lazy_default_base
  62. /**/
  63. #else
  64. #define BOOST_PARAMETER_lazy_default_fallback \
  65. ::boost::parameter::aux::lazy_default
  66. /**/
  67. #endif
  68. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  69. #include <utility>
  70. namespace boost { namespace parameter { namespace aux {
  71. template <typename Keyword, typename Value>
  72. struct default_r_
  73. {
  74. inline BOOST_CONSTEXPR default_r_(Value&& x)
  75. : value(::std::forward<Value>(x))
  76. {
  77. }
  78. Value&& value;
  79. };
  80. }}} // namespace boost::parameter::aux
  81. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  82. #endif // include guard