Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:58:27

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file literal.hpp
0003 /// The literal\<\> terminal wrapper, and the proto::lit() function for
0004 /// creating literal\<\> wrappers.
0005 //
0006 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0007 //  Software License, Version 1.0. (See accompanying file
0008 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007
0011 #define BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007
0012 
0013 #include <boost/config.hpp>
0014 #include <boost/proto/proto_fwd.hpp>
0015 #include <boost/proto/expr.hpp>
0016 #include <boost/proto/traits.hpp>
0017 #include <boost/proto/extends.hpp>
0018 
0019 namespace boost { namespace proto
0020 {
0021     namespace utility
0022     {
0023         /// \brief A simple wrapper for a terminal, provided for
0024         /// ease of use.
0025         ///
0026         /// A simple wrapper for a terminal, provided for
0027         /// ease of use. In all cases, <tt>literal\<X\> l(x);</tt>
0028         /// is equivalent to <tt>terminal\<X\>::type l = {x};</tt>.
0029         ///
0030         /// The \c Domain template parameter defaults to
0031         /// \c proto::default_domain.
0032         template<
0033             typename T
0034           , typename Domain // = default_domain
0035         >
0036         struct literal
0037           : extends<basic_expr<tag::terminal, term<T>, 0>, literal<T, Domain>, Domain>
0038         {
0039         private:
0040             typedef basic_expr<tag::terminal, term<T>, 0> terminal_type;
0041             typedef extends<terminal_type, literal<T, Domain>, Domain> base_type;
0042             typedef literal<T, Domain> literal_t;
0043 
0044         public:
0045             typedef typename detail::term_traits<T>::value_type       value_type;
0046             typedef typename detail::term_traits<T>::reference        reference;
0047             typedef typename detail::term_traits<T>::const_reference  const_reference;
0048 
0049             literal()
0050               : base_type(terminal_type::make(T()))
0051             {}
0052 
0053 #ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
0054             literal(literal const &) = default;
0055 #endif
0056 
0057             template<typename U>
0058             literal(U &u)
0059               : base_type(terminal_type::make(u))
0060             {}
0061 
0062             template<typename U>
0063             literal(U const &u)
0064               : base_type(terminal_type::make(u))
0065             {}
0066 
0067             template<typename U>
0068             literal(literal<U, Domain> const &u)
0069               : base_type(terminal_type::make(u.get()))
0070             {}
0071 
0072             BOOST_PROTO_EXTENDS_USING_ASSIGN(literal_t)
0073 
0074             reference get()
0075             {
0076                 return proto::value(*this);
0077             }
0078 
0079             const_reference get() const
0080             {
0081                 return proto::value(*this);
0082             }
0083         };
0084     }
0085 
0086     /// \brief A helper function for creating a \c literal\<\> wrapper.
0087     /// \param t The object to wrap.
0088     /// \return literal\<T &\>(t)
0089     /// \attention The returned value holds the argument by reference.
0090     /// \throw nothrow
0091     template<typename T>
0092     inline literal<T &> const lit(T &t)
0093     {
0094         return literal<T &>(t);
0095     }
0096 
0097     /// \overload
0098     ///
0099     template<typename T>
0100     inline literal<T const &> const lit(T const &t)
0101     {
0102         #ifdef BOOST_MSVC
0103         #pragma warning(push)
0104         #pragma warning(disable: 4180) // warning C4180: qualifier applied to function type has no meaning; ignored
0105         #endif
0106 
0107         return literal<T const &>(t);
0108 
0109         #ifdef BOOST_MSVC
0110         #pragma warning(pop)
0111         #endif
0112     }
0113 
0114 }}
0115 
0116 #endif