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>
13
namespace boost { namespace parameter {
15
// Instances of unique specializations of keyword<...> serve to
16
// associate arguments with parameter names. For example:
18
// struct rate_; // parameter names
22
// keyword<rate_> rate; // keywords
23
// keyword<skew_> skew;
28
// f(rate = 1, skew = 2.4);
34
typename aux::tag<Tag, T>::type const
37
typedef typename aux::tag<Tag, T>::type result;
41
template <class Default>
42
aux::default_<Tag, Default>
43
operator|(Default& default_) const
45
return aux::default_<Tag, Default>(default_);
48
template <class Default>
49
aux::lazy_default<Tag, Default>
50
operator||(Default& default_) const
52
return aux::lazy_default<Tag, Default>(default_);
55
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
57
typename aux::tag<Tag, T const>::type const
58
operator=(T const& x) const
60
typedef typename aux::tag<Tag, T const>::type result;
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)
73
return aux::default_<Tag, const Default>(default_);
76
template <class Default>
77
aux::lazy_default<Tag, Default>
78
operator||(Default const& default_) const
79
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
83
return aux::lazy_default<Tag, Default>(default_);
87
public: // Insurance against ODR violations
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;
96
// This interface is deprecated
97
static keyword<Tag>& get()
99
return const_cast<keyword<Tag>&>(instance);
104
keyword<Tag> const keyword<Tag>::instance = {};
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 \
119
static char const* keyword_name() \
125
static ::boost::parameter::keyword<tag_namespace::name> const& name \
126
= ::boost::parameter::keyword<tag_namespace::name>::instance;
130
#define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
131
namespace tag_namespace \
135
static char const* keyword_name() \
143
::boost::parameter::keyword<tag_namespace::name> const& name \
144
= ::boost::parameter::keyword<tag_namespace::name>::instance;\
149
}} // namespace boost::parameter
151
#endif // KEYWORD_050328_HPP