1 ///////////////////////////////////////////////////////////////////////////////
3 /// The literal\<\> terminal wrapper, and the proto::lit() function for
4 /// creating literal\<\> wrappers.
6 // Copyright 2008 Eric Niebler. Distributed under the Boost
7 // Software License, Version 1.0. (See accompanying file
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007
11 #define BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007
13 #include <boost/proto/detail/prefix.hpp>
14 #include <boost/config.hpp>
15 #include <boost/proto/proto_fwd.hpp>
16 #include <boost/proto/expr.hpp>
17 #include <boost/proto/traits.hpp>
18 #include <boost/proto/extends.hpp>
19 #include <boost/proto/detail/suffix.hpp>
21 namespace boost
{ namespace proto
25 /// \brief A simple wrapper for a terminal, provided for
28 /// A simple wrapper for a terminal, provided for
29 /// ease of use. In all cases, <tt>literal\<X\> l(x);</tt>
30 /// is equivalent to <tt>terminal\<X\>::::type l = {x};</tt>.
32 /// The \c Domain template parameter defaults to
33 /// \c proto::default_domain.
36 , typename Domain
BOOST_PROTO_WHEN_BUILDING_DOCS(= default_domain
)
39 : extends
<expr
<tag::terminal
, term
<T
> >, literal
<T
, Domain
>, Domain
>
42 typedef expr
<tag::terminal
, term
<T
> > terminal_type
;
43 typedef extends
<terminal_type
, literal
<T
, Domain
>, Domain
> base_type
;
46 typedef typename
detail::term_traits
<T
>::value_type value_type
;
47 typedef typename
detail::term_traits
<T
>::reference reference
;
48 typedef typename
detail::term_traits
<T
>::const_reference const_reference
;
52 : base_type(terminal_type::make(u
))
57 : base_type(terminal_type::make(u
))
61 literal(literal
<U
, Domain
> const &u
)
62 : base_type(terminal_type::make(u
.get()))
65 using base_type::operator =;
69 return proto::value(*this);
72 const_reference
get() const
74 return proto::value(*this);
79 /// \brief A helper function for creating a \c literal\<\> wrapper.
80 /// \param t The object to wrap.
81 /// \return literal\<T &\>(t)
82 /// \attention The returned value holds the argument by reference.
85 inline literal
<T
&> const lit(T
&t
)
87 return literal
<T
&>(t
);
93 inline literal
<T
const &> const lit(T
const &t
)
97 #pragma warning(disable: 4180) // warning C4180: qualifier applied to function type has no meaning; ignored
100 return literal
<T
const &>(t
);