Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/spirit/fusion/sequence/get.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.9 KB
Line 
1/*=============================================================================
2    Copyright (c) 1999-2003 Jaakko Järvi
3    Copyright (c) 2001-2003 Joel de Guzman
4    Copyright (c) 2004 Peder Holt
5
6    Use, modification and distribution is subject to the Boost Software
7    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8    http://www.boost.org/LICENSE_1_0.txt)
9==============================================================================*/
10#if !defined(FUSION_SEQUENCE_GET_HPP)
11#define FUSION_SEQUENCE_GET_HPP
12
13#include <boost/spirit/fusion/sequence/at.hpp>
14#include <boost/spirit/fusion/sequence/tuple_element.hpp>
15#include <boost/spirit/fusion/sequence/detail/sequence_base.hpp>
16#include <boost/type_traits/add_reference.hpp>
17
18namespace boost { namespace fusion
19{
20    namespace detail
21    {
22        template<int N>
23        struct pair_element;
24
25        template<>
26        struct pair_element<0>
27        {
28            template<typename T1, typename T2>
29            static BOOST_DEDUCED_TYPENAME add_reference<T1>::type
30            get(std::pair<T1, T2>& pr)
31            {
32                return pr.first;
33            }
34
35            template<typename T1, typename T2>
36            static BOOST_DEDUCED_TYPENAME add_reference<const T1>::type
37            get(const std::pair<T1, T2>& pr)
38            {
39                return pr.first;
40            }
41        };
42
43        template<>
44        struct pair_element<1>
45        {
46            template<typename T1, typename T2>
47            static BOOST_DEDUCED_TYPENAME add_reference<T2>::type
48            get(std::pair<T1, T2>& pr)
49            {
50                return pr.second;
51            }
52
53            template<typename T1, typename T2>
54            static BOOST_DEDUCED_TYPENAME add_reference<const T2>::type
55            get(const std::pair<T1, T2>& pr)
56            {
57                return pr.second;
58            }
59        };
60    }
61
62    ///////////////////////////////////////////////////////////////////////////
63    //
64    //  get function
65    //
66    //      Given a constant integer N and a sequence, returns a reference to
67    //      the Nth element of the sequence. (N is a zero based index). Usage:
68    //
69    //          get<N>(seq)
70    //
71    //  This function is provided here for compatibility with the tuples TR1
72    //  specification. This function forwards to at<N>(seq).
73    //
74    ///////////////////////////////////////////////////////////////////////////
75    template <int N, typename Sequence>
76    inline typename meta::at_c<Sequence const, N>::type
77    get(sequence_base<Sequence> const& seq FUSION_GET_MSVC_WORKAROUND)
78    {
79        typedef meta::at_c<Sequence const, N> at_meta;
80        return meta::at_impl<BOOST_DEDUCED_TYPENAME at_meta::seq::tag>::
81            template apply<BOOST_DEDUCED_TYPENAME at_meta::seq const, N>::call(
82                at_meta::seq_converter::convert_const(seq.cast()));
83
84//        return at<N>(seq.cast());
85    }
86
87    template <int N, typename Sequence>
88    inline typename meta::at_c<Sequence, N>::type
89    get(sequence_base<Sequence>& seq FUSION_GET_MSVC_WORKAROUND)
90    {
91        typedef meta::at_c<Sequence, N> at_meta;
92        return meta::at_impl<BOOST_DEDUCED_TYPENAME at_meta::seq::tag>::
93            template apply<BOOST_DEDUCED_TYPENAME at_meta::seq, N>::call(
94                at_meta::seq_converter::convert(seq.cast()));
95//        return at<N>(seq.cast());
96    }
97
98    template<int N, typename T1, typename T2>
99    inline BOOST_DEDUCED_TYPENAME boost::add_reference<
100        BOOST_DEDUCED_TYPENAME tuple_element<N, std::pair<T1, T2> >::type>::type
101    get(std::pair<T1, T2>& pr)
102    {
103        return detail::pair_element<N>::get(pr);
104    }
105
106    template<int N, typename T1, typename T2>
107    inline BOOST_DEDUCED_TYPENAME boost::add_reference<
108        const BOOST_DEDUCED_TYPENAME tuple_element<N, std::pair<T1, T2> >::type>::type
109    get(const std::pair<T1, T2>& pr)
110    {
111        return detail::pair_element<N>::get(pr);
112    }
113}}
114
115#endif
116
Note: See TracBrowser for help on using the repository browser.