/////////////////////////////////////////////////////////////////////////////// /// \file literal.hpp /// The literal\<\> terminal wrapper, and the proto::lit() function for /// creating literal\<\> wrappers. // // Copyright 2008 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007 #define BOOST_PROTO_LITERAL_HPP_EAN_01_03_2007 #include #include #include #include #include namespace boost { namespace proto { namespace utility { /// \brief A simple wrapper for a terminal, provided for /// ease of use. /// /// A simple wrapper for a terminal, provided for /// ease of use. In all cases, literal\ l(x); /// is equivalent to terminal\::type l = {x};. /// /// The \c Domain template parameter defaults to /// \c proto::default_domain. template< typename T , typename Domain // = default_domain > struct literal : extends, 0>, literal, Domain> { private: typedef basic_expr, 0> terminal_type; typedef extends, Domain> base_type; typedef literal literal_t; public: typedef typename detail::term_traits::value_type value_type; typedef typename detail::term_traits::reference reference; typedef typename detail::term_traits::const_reference const_reference; literal() : base_type(terminal_type::make(T())) {} template literal(U &u) : base_type(terminal_type::make(u)) {} template literal(U const &u) : base_type(terminal_type::make(u)) {} template literal(literal const &u) : base_type(terminal_type::make(u.get())) {} BOOST_PROTO_EXTENDS_USING_ASSIGN(literal_t) reference get() { return proto::value(*this); } const_reference get() const { return proto::value(*this); } }; } /// \brief A helper function for creating a \c literal\<\> wrapper. /// \param t The object to wrap. /// \return literal\(t) /// \attention The returned value holds the argument by reference. /// \throw nothrow template inline literal const lit(T &t) { return literal(t); } /// \overload /// template inline literal const lit(T const &t) { #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable: 4180) // warning C4180: qualifier applied to function type has no meaning; ignored #endif return literal(t); #ifdef BOOST_MSVC #pragma warning(pop) #endif } }} #endif