[857] | 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_ITERATOR_HPP)
|
---|
| 10 | #define FUSION_SEQUENCE_AS_FUSION_ITERATOR_HPP
|
---|
| 11 |
|
---|
| 12 | #include <boost/spirit/fusion/iterator/is_iterator.hpp>
|
---|
| 13 | #include <boost/spirit/fusion/iterator/type_sequence_iterator.hpp>
|
---|
| 14 | #include <boost/mpl/if.hpp>
|
---|
| 15 | #include <boost/mpl/bool.hpp>
|
---|
| 16 |
|
---|
| 17 | namespace boost { namespace fusion
|
---|
| 18 | {
|
---|
| 19 | // Test T. If it is a fusion iterator, return a reference to it.
|
---|
| 20 | // else, assume it is an mpl iterator.
|
---|
| 21 |
|
---|
| 22 | namespace as_fusion_iterator_detail {
|
---|
| 23 | template <typename T>
|
---|
| 24 | static T const&
|
---|
| 25 | convert(T const& x, mpl::true_)
|
---|
| 26 | {
|
---|
| 27 | return x;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | template <typename T>
|
---|
| 31 | static type_sequence_iterator<T>
|
---|
| 32 | convert(T const& x, mpl::false_)
|
---|
| 33 | {
|
---|
| 34 | return type_sequence_iterator<T>();
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | template <typename T>
|
---|
| 39 | struct as_fusion_iterator
|
---|
| 40 | {
|
---|
| 41 | typedef typename
|
---|
| 42 | mpl::if_<
|
---|
| 43 | fusion::is_iterator<T>
|
---|
| 44 | , T
|
---|
| 45 | , type_sequence_iterator<T>
|
---|
| 46 | >::type
|
---|
| 47 | type;
|
---|
| 48 |
|
---|
| 49 | static typename
|
---|
| 50 | mpl::if_<
|
---|
| 51 | fusion::is_iterator<T>
|
---|
| 52 | , T const&
|
---|
| 53 | , type_sequence_iterator<T>
|
---|
| 54 | >::type
|
---|
| 55 | convert(T const& x);
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | template <typename T>
|
---|
| 59 | typename
|
---|
| 60 | mpl::if_<
|
---|
| 61 | fusion::is_iterator<T>
|
---|
| 62 | , T const&
|
---|
| 63 | , type_sequence_iterator<T>
|
---|
| 64 | >::type
|
---|
| 65 | as_fusion_iterator<T>::convert(T const& x)
|
---|
| 66 | {
|
---|
| 67 | return as_fusion_iterator_detail::convert(x, fusion::is_iterator<T>());
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | }}
|
---|
| 71 |
|
---|
| 72 | #endif
|
---|