default.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 BOOST_PARAMETER_AUX_DEFAULT_HPP
  7. #define BOOST_PARAMETER_AUX_DEFAULT_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. #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
  79. // MSVC 2015 miscompiles moves for classes containing rvalue ref members
  80. // using the default generated move constructor
  81. // when moving into a function
  82. // https://github.com/boostorg/parameter/pull/109
  83. inline BOOST_CONSTEXPR default_r_(default_r_&& x)
  84. : value(::std::forward<Value>(x.value))
  85. {
  86. }
  87. #endif
  88. Value&& value;
  89. };
  90. }}} // namespace boost::parameter::aux
  91. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  92. #endif // include guard