/Src/Dependencies/Boost/boost/parameter/keyword.hpp

http://hadesmem.googlecode.com/ · C++ Header · 152 lines · 100 code · 22 blank · 30 comment · 2 complexity · bf262a1158c4bb122539f021d7a5577c MD5 · raw file

  1. // Copyright Daniel Wallin, David Abrahams 2005. Use, modification and
  2. // distribution is subject to the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef KEYWORD_050328_HPP
  6. #define KEYWORD_050328_HPP
  7. #include <boost/parameter/aux_/unwrap_cv_reference.hpp>
  8. #include <boost/parameter/aux_/tag.hpp>
  9. #include <boost/parameter/aux_/default.hpp>
  10. namespace boost { namespace parameter {
  11. // Instances of unique specializations of keyword<...> serve to
  12. // associate arguments with parameter names. For example:
  13. //
  14. // struct rate_; // parameter names
  15. // struct skew_;
  16. // namespace
  17. // {
  18. // keyword<rate_> rate; // keywords
  19. // keyword<skew_> skew;
  20. // }
  21. //
  22. // ...
  23. //
  24. // f(rate = 1, skew = 2.4);
  25. //
  26. template <class Tag>
  27. struct keyword
  28. {
  29. template <class T>
  30. typename aux::tag<Tag, T>::type const
  31. operator=(T& x) const
  32. {
  33. typedef typename aux::tag<Tag, T>::type result;
  34. return result(x);
  35. }
  36. template <class Default>
  37. aux::default_<Tag, Default>
  38. operator|(Default& default_) const
  39. {
  40. return aux::default_<Tag, Default>(default_);
  41. }
  42. template <class Default>
  43. aux::lazy_default<Tag, Default>
  44. operator||(Default& default_) const
  45. {
  46. return aux::lazy_default<Tag, Default>(default_);
  47. }
  48. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
  49. template <class T>
  50. typename aux::tag<Tag, T const>::type const
  51. operator=(T const& x) const
  52. {
  53. typedef typename aux::tag<Tag, T const>::type result;
  54. return result(x);
  55. }
  56. #endif
  57. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
  58. template <class Default>
  59. aux::default_<Tag, const Default>
  60. operator|(const Default& default_) const
  61. #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
  62. volatile
  63. #endif
  64. {
  65. return aux::default_<Tag, const Default>(default_);
  66. }
  67. template <class Default>
  68. aux::lazy_default<Tag, Default>
  69. operator||(Default const& default_) const
  70. #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
  71. volatile
  72. #endif
  73. {
  74. return aux::lazy_default<Tag, Default>(default_);
  75. }
  76. #endif
  77. public: // Insurance against ODR violations
  78. // People will need to define these keywords in header files. To
  79. // prevent ODR violations, it's important that the keyword used in
  80. // every instantiation of a function template is the same object.
  81. // We provide a reference to a common instance of each keyword
  82. // object and prevent construction by users.
  83. static keyword<Tag> const instance;
  84. // This interface is deprecated
  85. static keyword<Tag>& get()
  86. {
  87. return const_cast<keyword<Tag>&>(instance);
  88. }
  89. };
  90. template <class Tag>
  91. keyword<Tag> const keyword<Tag>::instance = {};
  92. // Reduces boilerplate required to declare and initialize keywords
  93. // without violating ODR. Declares a keyword tag type with the given
  94. // name in namespace tag_namespace, and declares and initializes a
  95. // reference in an anonymous namespace to a singleton instance of that
  96. // type.
  97. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  98. # define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
  99. namespace tag_namespace \
  100. { \
  101. struct name \
  102. { \
  103. static char const* keyword_name() \
  104. { \
  105. return #name; \
  106. } \
  107. }; \
  108. } \
  109. static ::boost::parameter::keyword<tag_namespace::name> const& name \
  110. = ::boost::parameter::keyword<tag_namespace::name>::instance;
  111. #else
  112. #define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
  113. namespace tag_namespace \
  114. { \
  115. struct name \
  116. { \
  117. static char const* keyword_name() \
  118. { \
  119. return #name; \
  120. } \
  121. }; \
  122. } \
  123. namespace \
  124. { \
  125. ::boost::parameter::keyword<tag_namespace::name> const& name \
  126. = ::boost::parameter::keyword<tag_namespace::name>::instance;\
  127. }
  128. #endif
  129. }} // namespace boost::parameter
  130. #endif // KEYWORD_050328_HPP