fix doc example typo
[boost.git] / boost / proto / literal.hpp
blob7fb8094ca1e065deedd6a93547ed5df5bf8e1606
1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file literal.hpp
3 /// The literal\<\> terminal wrapper, and the proto::lit() function for
4 /// creating literal\<\> wrappers.
5 //
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
23 namespace utility
25 /// \brief A simple wrapper for a terminal, provided for
26 /// ease of use.
27 ///
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>.
31 ///
32 /// The \c Domain template parameter defaults to
33 /// \c proto::default_domain.
34 template<
35 typename T
36 , typename Domain BOOST_PROTO_WHEN_BUILDING_DOCS(= default_domain)
38 struct literal
39 : extends<expr<tag::terminal, term<T> >, literal<T, Domain>, Domain>
41 private:
42 typedef expr<tag::terminal, term<T> > terminal_type;
43 typedef extends<terminal_type, literal<T, Domain>, Domain> base_type;
45 public:
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;
50 template<typename U>
51 literal(U &u)
52 : base_type(terminal_type::make(u))
55 template<typename U>
56 literal(U const &u)
57 : base_type(terminal_type::make(u))
60 template<typename U>
61 literal(literal<U, Domain> const &u)
62 : base_type(terminal_type::make(u.get()))
65 using base_type::operator =;
67 reference get()
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.
83 /// \throw nothrow
84 template<typename T>
85 inline literal<T &> const lit(T &t)
87 return literal<T &>(t);
90 /// \overload
91 ///
92 template<typename T>
93 inline literal<T const &> const lit(T const &t)
95 #ifdef BOOST_MSVC
96 #pragma warning(push)
97 #pragma warning(disable: 4180) // warning C4180: qualifier applied to function type has no meaning; ignored
98 #endif
100 return literal<T const &>(t);
102 #ifdef BOOST_MSVC
103 #pragma warning(pop)
104 #endif
109 #endif