source: NonGTP/Boost/boost/spirit/fusion/iterator/deref.hpp @ 857

Revision 857, 3.2 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_ITERATOR_DEREF_HPP)
10#define FUSION_ITERATOR_DEREF_HPP
11
12#include <boost/spirit/fusion/detail/config.hpp>
13#include <boost/spirit/fusion/iterator/detail/iterator_base.hpp>
14#include <boost/spirit/fusion/iterator/as_fusion_iterator.hpp>
15#include <boost/utility/enable_if.hpp>
16#include <boost/type_traits/is_const.hpp>
17
18namespace boost { namespace fusion
19{
20    namespace meta
21    {
22        template <typename Tag>
23        struct deref_impl
24        {
25            template <typename Iterator>
26            struct apply {};
27        };
28
29        template <typename Iterator>
30        struct deref
31        {
32            typedef as_fusion_iterator<Iterator> converter;
33            typedef typename converter::type iter;
34
35            typedef typename
36                deref_impl<FUSION_GET_TAG(iter)>::
37                    template apply<iter>::type
38            type;
39        };
40    }
41
42    namespace deref_detail {
43        template <typename Iterator>
44        typename meta::deref<Iterator>::type
45        deref(Iterator const& i,mpl::true_)
46        {
47            typedef as_fusion_iterator<Iterator> converter;
48            typedef typename converter::type iter;
49
50            typename meta::deref<iter>::type result =
51                meta::deref_impl<FUSION_GET_TAG(iter)>::
52                    template apply<iter>::call(converter::convert(i));
53            return result;
54        }
55
56        template <typename Iterator>
57        inline typename meta::deref<Iterator>::type
58        deref(Iterator& i,mpl::false_)
59        {
60            typedef as_fusion_iterator<Iterator> converter;
61            typedef typename converter::type iter;
62
63            typename meta::deref<iter>::type result =
64                meta::deref_impl<FUSION_GET_TAG(iter)>::
65                    template apply<iter>::call(converter::convert(i));
66            return result;
67        }
68    }
69
70    template <typename Iterator>
71    typename meta::deref<Iterator>::type
72    deref(Iterator& i) {
73        return deref_detail::deref(i,is_const<Iterator>());
74    }
75
76    template <typename Iterator>
77    typename meta::deref<Iterator>::type
78    deref(Iterator const & i) {
79        return deref_detail::deref(i,is_const<Iterator const>());
80    }
81
82    template <typename Iterator>
83    typename meta::deref<Iterator>::type
84    operator*(iterator_base<Iterator> const& i)
85    {
86        return fusion::deref(i.cast());
87    }
88
89    template <typename Iterator>
90    inline typename meta::deref<Iterator>::type
91    operator*(iterator_base<Iterator>& i)
92    {
93        return fusion::deref(i.cast());
94    }
95
96    // Note: VC7.1 has a problem when we pass the return value directly.
97    // Try removing the named temporary. This only happens on debug builds.
98    // It seems to be a return value optimization bug.
99}}
100
101#endif
Note: See TracBrowser for help on using the repository browser.