source: NonGTP/Boost/boost/spirit/fusion/sequence/as_fusion_sequence.hpp @ 857

Revision 857, 2.8 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2003 Joel de Guzman
3    Copyright (c) 2004 Peder Holt
4
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(FUSION_SEQUENCE_AS_FUSION_SEQUENCE_HPP)
10#define FUSION_SEQUENCE_AS_FUSION_SEQUENCE_HPP
11
12#include <boost/spirit/fusion/sequence/is_sequence.hpp>
13#include <boost/spirit/fusion/sequence/type_sequence.hpp>
14#include <boost/mpl/is_sequence.hpp>
15#include <boost/mpl/if.hpp>
16#include <boost/mpl/bool.hpp>
17#include <boost/static_assert.hpp>
18
19namespace boost { namespace fusion
20{
21    //  Test T. If it is a fusion sequence, return a reference to it.
22    //  else, assume it is an mpl sequence. Fail if it is not.
23
24    namespace fusion_sequence_detail {
25        template<typename T>
26        static T const& convert_const(T const& x, mpl::true_) {
27            return x;
28        }
29        template<typename T>
30        static type_sequence<T const> convert_const(T const& x, mpl::false_) {
31            BOOST_STATIC_ASSERT(mpl::is_sequence<T>::value);
32            return type_sequence<T const>();
33        }
34        template<typename T>
35        static T& convert(T& x, mpl::true_)
36        {
37            return x;
38        }
39
40        template<typename T>
41        static type_sequence<T> convert(T& x, mpl::false_)
42        {
43            BOOST_STATIC_ASSERT(mpl::is_sequence<T>::value);
44            return type_sequence<T>();
45        }
46    }
47
48    template <typename T>
49    struct as_fusion_sequence {
50        typedef typename
51            mpl::if_<
52                fusion::is_sequence<T>
53              , T
54              , type_sequence<T>
55            >::type
56        type;
57
58        static typename
59        mpl::if_<
60            fusion::is_sequence<T>
61          , T const&
62          , type_sequence<T const>
63        >::type
64        convert_const(T const& x);
65       
66        static typename
67        mpl::if_<
68            fusion::is_sequence<T>
69          , T &
70          , type_sequence<T>
71        >::type
72        convert(T& x);
73    };
74
75    template<typename T>
76    typename
77    mpl::if_<
78        fusion::is_sequence<T>
79      , T const&
80      , type_sequence<T const>
81    >::type
82    as_fusion_sequence<T>::convert_const(T const& x) {
83        return fusion_sequence_detail::convert_const(x,fusion::is_sequence<T>());
84    }
85
86    template<typename T>
87    typename
88    mpl::if_<
89        fusion::is_sequence<T>
90      , T&
91      , type_sequence<T>
92    >::type
93    as_fusion_sequence<T>::convert(T& x) {
94        return fusion_sequence_detail::convert(x,fusion::is_sequence<T>());
95    }
96}}
97
98
99#endif
Note: See TracBrowser for help on using the repository browser.