1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_MATCH_ATTR_TRAITS_IPP)
10 #define BOOST_SPIRIT_MATCH_ATTR_TRAITS_IPP
12 #include <boost/optional.hpp>
13 #include <boost/mpl/bool.hpp>
14 #include <boost/mpl/or.hpp>
15 #include <boost/type_traits/is_convertible.hpp>
16 #include <boost/type_traits/is_same.hpp>
18 namespace boost { namespace spirit {
20 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
25 struct match_attr_traits
28 boost::optional<T>::reference_const_type
31 // case where src *IS* convertible to T (dest)
32 template <typename T2>
34 convert(boost::optional<T>& dest, T2 const& src, mpl::true_)
39 // case where src *IS NOT* convertible to T (dest)
40 template <typename T2>
42 convert(boost::optional<T>& dest, T2 const& /*src*/, mpl::false_)
48 convert(boost::optional<T>& dest, nil_t/*src*/)
53 template <typename T2>
55 convert(boost::optional<T>& dest, T2 const& src)
57 convert(dest, src, is_convertible<T2, T>());
60 template <typename OtherMatchT>
62 copy(boost::optional<T>& dest, OtherMatchT const& src)
64 if (src.has_valid_attribute())
65 convert(dest, src.value());
68 template <typename OtherMatchT>
70 assign(boost::optional<T>& dest, OtherMatchT const& src)
72 if (src.has_valid_attribute())
73 convert(dest, src.value());
79 template <typename ValueT>
81 set_value(boost::optional<T>& dest, ValueT const& val, mpl::false_)
87 template <typename ValueT>
89 set_value(boost::optional<T>& dest, ValueT const& val, mpl::true_)
97 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
99 }} // namespace boost::spirit::impl