comparison DEPENDENCIES/generic/include/boost/parameter/keyword.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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
6 #ifndef KEYWORD_050328_HPP
7 #define KEYWORD_050328_HPP
8
9 #include <boost/parameter/aux_/unwrap_cv_reference.hpp>
10 #include <boost/parameter/aux_/tag.hpp>
11 #include <boost/parameter/aux_/default.hpp>
12
13 namespace boost { namespace parameter {
14
15 // Instances of unique specializations of keyword<...> serve to
16 // associate arguments with parameter names. For example:
17 //
18 // struct rate_; // parameter names
19 // struct skew_;
20 // namespace
21 // {
22 // keyword<rate_> rate; // keywords
23 // keyword<skew_> skew;
24 // }
25 //
26 // ...
27 //
28 // f(rate = 1, skew = 2.4);
29 //
30 template <class Tag>
31 struct keyword
32 {
33 template <class T>
34 typename aux::tag<Tag, T>::type const
35 operator=(T& x) const
36 {
37 typedef typename aux::tag<Tag, T>::type result;
38 return result(x);
39 }
40
41 template <class Default>
42 aux::default_<Tag, Default>
43 operator|(Default& default_) const
44 {
45 return aux::default_<Tag, Default>(default_);
46 }
47
48 template <class Default>
49 aux::lazy_default<Tag, Default>
50 operator||(Default& default_) const
51 {
52 return aux::lazy_default<Tag, Default>(default_);
53 }
54
55 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
56 template <class T>
57 typename aux::tag<Tag, T const>::type const
58 operator=(T const& x) const
59 {
60 typedef typename aux::tag<Tag, T const>::type result;
61 return result(x);
62 }
63 #endif
64
65 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
66 template <class Default>
67 aux::default_<Tag, const Default>
68 operator|(const Default& default_) const
69 #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
70 volatile
71 #endif
72 {
73 return aux::default_<Tag, const Default>(default_);
74 }
75
76 template <class Default>
77 aux::lazy_default<Tag, Default>
78 operator||(Default const& default_) const
79 #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
80 volatile
81 #endif
82 {
83 return aux::lazy_default<Tag, Default>(default_);
84 }
85 #endif
86
87 public: // Insurance against ODR violations
88
89 // People will need to define these keywords in header files. To
90 // prevent ODR violations, it's important that the keyword used in
91 // every instantiation of a function template is the same object.
92 // We provide a reference to a common instance of each keyword
93 // object and prevent construction by users.
94 static keyword<Tag> const instance;
95
96 // This interface is deprecated
97 static keyword<Tag>& get()
98 {
99 return const_cast<keyword<Tag>&>(instance);
100 }
101 };
102
103 template <class Tag>
104 keyword<Tag> const keyword<Tag>::instance = {};
105
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
110 // type.
111
112 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
113
114 # define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
115 namespace tag_namespace \
116 { \
117 struct name \
118 { \
119 static char const* keyword_name() \
120 { \
121 return #name; \
122 } \
123 }; \
124 } \
125 static ::boost::parameter::keyword<tag_namespace::name> const& name \
126 = ::boost::parameter::keyword<tag_namespace::name>::instance;
127
128 #else
129
130 #define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
131 namespace tag_namespace \
132 { \
133 struct name \
134 { \
135 static char const* keyword_name() \
136 { \
137 return #name; \
138 } \
139 }; \
140 } \
141 namespace \
142 { \
143 ::boost::parameter::keyword<tag_namespace::name> const& name \
144 = ::boost::parameter::keyword<tag_namespace::name>::instance;\
145 }
146
147 #endif
148
149 }} // namespace boost::parameter
150
151 #endif // KEYWORD_050328_HPP
152