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)
6 #ifndef KEYWORD_050328_HPP
7 #define KEYWORD_050328_HPP
9 #include <boost/parameter/aux_/unwrap_cv_reference.hpp>
10 #include <boost/parameter/aux_/tag.hpp>
11 #include <boost/parameter/aux_/default.hpp>
12 #include <boost/noncopyable.hpp>
14 namespace boost { namespace parameter {
16 // Instances of unique specializations of keyword<...> serve to
17 // associate arguments with parameter names. For example:
19 // struct rate_; // parameter names
23 // keyword<rate_> rate; // keywords
24 // keyword<skew_> skew;
29 // f(rate = 1, skew = 2.4);
32 struct keyword : noncopyable
35 typename aux::tag<Tag, T>::type
38 typedef typename aux::tag<Tag, T>::type result;
42 template <class Default>
43 aux::default_<Tag, Default>
44 operator|(Default& default_) const
46 return aux::default_<Tag, Default>(default_);
49 template <class Default>
50 aux::lazy_default<Tag, Default>
51 operator||(Default& default_) const
53 return aux::lazy_default<Tag, Default>(default_);
56 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
58 typename aux::tag<Tag, T const>::type
59 operator=(T const& x) const
61 typedef typename aux::tag<Tag, T const>::type result;
66 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
67 template <class Default>
68 aux::default_<Tag, const Default>
69 operator|(const Default& default_) const
70 #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
74 return aux::default_<Tag, const Default>(default_);
77 template <class Default>
78 aux::lazy_default<Tag, Default>
79 operator||(Default const& default_) const
80 #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
84 return aux::lazy_default<Tag, Default>(default_);
88 public: // Insurance against ODR violations
90 // People will need to define these keywords in header files. To
91 // prevent ODR violations, it's important that the keyword used in
92 // every instantiation of a function template is the same object.
93 // We provide a reference to a common instance of each keyword
94 // object and prevent construction by users.
96 static keyword<Tag>& get()
98 static keyword<Tag> result;
106 // Reduces boilerplate required to declare and initialize keywords
107 // without violating ODR. Declares a keyword tag type with the given
108 // name in namespace tag_namespace, and declares and initializes a
109 // reference in an anonymous namespace to a singleton instance of that
112 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
114 # define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
115 namespace tag_namespace { struct name; } \
116 static ::boost::parameter::keyword<tag_namespace::name>& name \
117 = ::boost::parameter::keyword<tag_namespace::name>::get();
121 #define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
122 namespace tag_namespace { struct name; } \
125 ::boost::parameter::keyword<tag_namespace::name>& name \
126 = ::boost::parameter::keyword<tag_namespace::name>::get(); \
131 }} // namespace boost::parameter
133 #endif // KEYWORD_050328_HPP