1 |
|
---|
2 | #ifndef BOOST_MPL_SET_AUX_AT_IMPL_HPP_INCLUDED
|
---|
3 | #define BOOST_MPL_SET_AUX_AT_IMPL_HPP_INCLUDED
|
---|
4 |
|
---|
5 | // Copyright Aleksey Gurtovoy 2003-2004
|
---|
6 | // Copyright David Abrahams 2003-2004
|
---|
7 | //
|
---|
8 | // Distributed under the Boost Software License, Version 1.0.
|
---|
9 | // (See accompanying file LICENSE_1_0.txt or copy at
|
---|
10 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
11 | //
|
---|
12 | // See http://www.boost.org/libs/mpl for documentation.
|
---|
13 |
|
---|
14 | // $Source: /cvsroot/boost/boost/boost/mpl/map/aux_/at_impl.hpp,v $
|
---|
15 | // $Date: 2004/12/14 14:05:31 $
|
---|
16 | // $Revision: 1.6 $
|
---|
17 |
|
---|
18 | #include <boost/mpl/at_fwd.hpp>
|
---|
19 | #include <boost/mpl/long.hpp>
|
---|
20 | #include <boost/mpl/map/aux_/tag.hpp>
|
---|
21 | #include <boost/mpl/aux_/order_impl.hpp>
|
---|
22 | #include <boost/mpl/aux_/overload_names.hpp>
|
---|
23 | #include <boost/mpl/aux_/type_wrapper.hpp>
|
---|
24 | #include <boost/mpl/aux_/ptr_to_ref.hpp>
|
---|
25 | #include <boost/mpl/aux_/static_cast.hpp>
|
---|
26 | #include <boost/mpl/aux_/config/typeof.hpp>
|
---|
27 | #include <boost/mpl/aux_/config/ctps.hpp>
|
---|
28 |
|
---|
29 | #if !defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
|
---|
30 | # include <boost/mpl/eval_if.hpp>
|
---|
31 | # include <boost/mpl/pair.hpp>
|
---|
32 | # include <boost/mpl/void.hpp>
|
---|
33 | # include <boost/mpl/aux_/config/static_constant.hpp>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | namespace boost { namespace mpl {
|
---|
37 |
|
---|
38 | #if defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
|
---|
39 |
|
---|
40 | template< typename Map, typename Key >
|
---|
41 | struct m_at
|
---|
42 | {
|
---|
43 | typedef aux::type_wrapper<Key> key_;
|
---|
44 | typedef __typeof__( BOOST_MPL_AUX_OVERLOAD_CALL_VALUE_BY_KEY(
|
---|
45 | Map
|
---|
46 | , BOOST_MPL_AUX_STATIC_CAST(key_*, 0)
|
---|
47 | ) ) type;
|
---|
48 | };
|
---|
49 |
|
---|
50 | template<>
|
---|
51 | struct at_impl< aux::map_tag >
|
---|
52 | {
|
---|
53 | template< typename Map, typename Key > struct apply
|
---|
54 | : aux::wrapped_type< typename m_at<
|
---|
55 | Map
|
---|
56 | , Key
|
---|
57 | >::type >
|
---|
58 | {
|
---|
59 | };
|
---|
60 | };
|
---|
61 |
|
---|
62 | // agurt 31/jan/04: two-step implementation for the sake of GCC 3.x
|
---|
63 | template< typename Map, long order >
|
---|
64 | struct item_by_order_impl
|
---|
65 | {
|
---|
66 | typedef __typeof__( BOOST_MPL_AUX_OVERLOAD_CALL_ITEM_BY_ORDER(
|
---|
67 | Map
|
---|
68 | , BOOST_MPL_AUX_STATIC_CAST(long_<order>*, 0)
|
---|
69 | ) ) type;
|
---|
70 | };
|
---|
71 |
|
---|
72 | template< typename Map, long order >
|
---|
73 | struct item_by_order
|
---|
74 | : aux::wrapped_type<
|
---|
75 | typename item_by_order_impl<Map,order>::type
|
---|
76 | >
|
---|
77 | {
|
---|
78 | };
|
---|
79 |
|
---|
80 | #else // BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES
|
---|
81 |
|
---|
82 | # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
83 |
|
---|
84 | template< typename Map, long n > struct m_at
|
---|
85 | {
|
---|
86 | typedef void_ type;
|
---|
87 | };
|
---|
88 |
|
---|
89 | # else
|
---|
90 |
|
---|
91 | template< long n > struct m_at_impl
|
---|
92 | {
|
---|
93 | template< typename Map > struct result_
|
---|
94 | {
|
---|
95 | typedef void_ type;
|
---|
96 | };
|
---|
97 | };
|
---|
98 |
|
---|
99 | template< typename Map, long n > struct m_at
|
---|
100 | {
|
---|
101 | typedef typename m_at_impl<n>::result_<Map>::type type;
|
---|
102 | };
|
---|
103 |
|
---|
104 | # endif
|
---|
105 |
|
---|
106 |
|
---|
107 | template<>
|
---|
108 | struct at_impl< aux::map_tag >
|
---|
109 | {
|
---|
110 | template< typename Map, typename Key > struct apply
|
---|
111 | {
|
---|
112 | typedef typename m_at< Map, (x_order_impl<Map,Key>::value - 2) >::type item_;
|
---|
113 | typedef typename eval_if<
|
---|
114 | is_void_<item_>
|
---|
115 | , void_
|
---|
116 | , second<item_>
|
---|
117 | >::type type;
|
---|
118 | };
|
---|
119 | };
|
---|
120 |
|
---|
121 | template< typename Map, long order > struct is_item_masked
|
---|
122 | {
|
---|
123 | BOOST_STATIC_CONSTANT(bool, value =
|
---|
124 | sizeof( BOOST_MPL_AUX_OVERLOAD_CALL_IS_MASKED(
|
---|
125 | Map
|
---|
126 | , BOOST_MPL_AUX_STATIC_CAST(long_<order>*, 0)
|
---|
127 | ) ) == sizeof(aux::yes_tag)
|
---|
128 | );
|
---|
129 | };
|
---|
130 |
|
---|
131 | template< typename Map, long order > struct item_by_order
|
---|
132 | {
|
---|
133 | typedef typename eval_if_c<
|
---|
134 | is_item_masked<Map,order>::value
|
---|
135 | , void_
|
---|
136 | , m_at<Map,(order - 2)>
|
---|
137 | >::type type;
|
---|
138 | };
|
---|
139 |
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | }}
|
---|
143 |
|
---|
144 | #endif // BOOST_MPL_SET_AUX_AT_IMPL_HPP_INCLUDED
|
---|