]>
Commit | Line | Data |
---|---|---|
1 | /*============================================================================= | |
2 | Copyright (c) 2001-2014 Joel de Guzman | |
3 | Copyright (c) 2001-2011 Hartmut Kaiser | |
4 | http://spirit.sourceforge.net/ | |
5 | ||
6 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
7 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | =============================================================================*/ | |
9 | #if !defined(BOOST_SPIRIT_X3_OPTIONAL_TRAITS_FEBRUARY_06_2007_1001AM) | |
10 | #define BOOST_SPIRIT_X3_OPTIONAL_TRAITS_FEBRUARY_06_2007_1001AM | |
11 | ||
12 | #include <boost/spirit/home/x3/support/unused.hpp> | |
13 | #include <boost/optional/optional.hpp> | |
14 | #include <boost/mpl/identity.hpp> | |
15 | ||
16 | namespace boost { namespace spirit { namespace x3 { namespace traits | |
17 | { | |
18 | /////////////////////////////////////////////////////////////////////////// | |
19 | template <typename T, typename Enable = void> | |
20 | struct is_optional | |
21 | : mpl::false_ | |
22 | {}; | |
23 | ||
24 | template <typename T> | |
25 | struct is_optional<boost::optional<T>> | |
26 | : mpl::true_ | |
27 | {}; | |
28 | ||
29 | /////////////////////////////////////////////////////////////////////////// | |
30 | // build_optional | |
31 | // | |
32 | // Build a boost::optional from T. Return unused_type if T is unused_type. | |
33 | /////////////////////////////////////////////////////////////////////////// | |
34 | template <typename T> | |
35 | struct build_optional | |
36 | { | |
37 | typedef boost::optional<T> type; | |
38 | }; | |
39 | ||
40 | template <typename T> | |
41 | struct build_optional<boost::optional<T> > | |
42 | { | |
43 | typedef boost::optional<T> type; | |
44 | }; | |
45 | ||
46 | template <> | |
47 | struct build_optional<unused_type> | |
48 | { | |
49 | typedef unused_type type; | |
50 | }; | |
51 | ||
52 | /////////////////////////////////////////////////////////////////////////// | |
53 | // optional_value | |
54 | // | |
55 | // Get the optional's value_type. Handles unused_type as well. | |
56 | /////////////////////////////////////////////////////////////////////////// | |
57 | template <typename T> | |
58 | struct optional_value : mpl::identity<T> {}; | |
59 | ||
60 | template <typename T> | |
61 | struct optional_value<boost::optional<T> > | |
62 | : mpl::identity<T> {}; | |
63 | ||
64 | template <> | |
65 | struct optional_value<unused_type> | |
66 | : mpl::identity<unused_type> {}; | |
67 | ||
68 | template <> | |
69 | struct optional_value<unused_type const> | |
70 | : mpl::identity<unused_type> {}; | |
71 | ||
72 | }}}} | |
73 | ||
74 | #endif |