Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2006 Dan Marsden
|
Chris@16
|
4
|
Chris@16
|
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 ==============================================================================*/
|
Chris@16
|
8 #if !defined(BOOST_FUSION_AT_KEY_20060304_1755)
|
Chris@16
|
9 #define BOOST_FUSION_AT_KEY_20060304_1755
|
Chris@16
|
10
|
Chris@101
|
11 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
12 #include <boost/type_traits/is_const.hpp>
|
Chris@16
|
13 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
|
Chris@16
|
14 #include <boost/fusion/algorithm/query/find.hpp>
|
Chris@16
|
15 #include <boost/fusion/iterator/deref_data.hpp>
|
Chris@16
|
16 #include <boost/fusion/support/tag_of.hpp>
|
Chris@16
|
17 #include <boost/fusion/support/detail/access.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost { namespace fusion
|
Chris@16
|
20 {
|
Chris@16
|
21 // Special tags:
|
Chris@16
|
22 struct sequence_facade_tag;
|
Chris@16
|
23 struct boost_array_tag; // boost::array tag
|
Chris@16
|
24 struct mpl_sequence_tag; // mpl sequence tag
|
Chris@16
|
25 struct std_pair_tag; // std::pair tag
|
Chris@16
|
26
|
Chris@16
|
27 namespace extension
|
Chris@16
|
28 {
|
Chris@16
|
29 template <typename Tag>
|
Chris@16
|
30 struct at_key_impl
|
Chris@16
|
31 {
|
Chris@16
|
32 template <typename Seq, typename Key>
|
Chris@16
|
33 struct apply
|
Chris@16
|
34 {
|
Chris@16
|
35 typedef typename
|
Chris@16
|
36 result_of::deref_data<
|
Chris@16
|
37 typename result_of::find<Seq, Key>::type
|
Chris@16
|
38 >::type
|
Chris@16
|
39 type;
|
Chris@16
|
40
|
Chris@101
|
41 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
42 static type
|
Chris@16
|
43 call(Seq& seq)
|
Chris@16
|
44 {
|
Chris@16
|
45 return fusion::deref_data(fusion::find<Key>(seq));
|
Chris@16
|
46 }
|
Chris@16
|
47 };
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 template <>
|
Chris@16
|
51 struct at_key_impl<sequence_facade_tag>
|
Chris@16
|
52 {
|
Chris@16
|
53 template <typename Sequence, typename Key>
|
Chris@16
|
54 struct apply : Sequence::template at_key_impl<Sequence, Key> {};
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 template <>
|
Chris@16
|
58 struct at_key_impl<boost_array_tag>;
|
Chris@16
|
59
|
Chris@16
|
60 template <>
|
Chris@16
|
61 struct at_key_impl<mpl_sequence_tag>;
|
Chris@16
|
62
|
Chris@16
|
63 template <>
|
Chris@16
|
64 struct at_key_impl<std_pair_tag>;
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 namespace result_of
|
Chris@16
|
68 {
|
Chris@16
|
69 template <typename Sequence, typename Key>
|
Chris@16
|
70 struct at_key
|
Chris@16
|
71 : extension::at_key_impl<typename detail::tag_of<Sequence>::type>::
|
Chris@16
|
72 template apply<Sequence, Key>
|
Chris@16
|
73 {};
|
Chris@16
|
74 }
|
Chris@16
|
75
|
Chris@16
|
76 template <typename Key, typename Sequence>
|
Chris@101
|
77 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
78 inline typename
|
Chris@16
|
79 lazy_disable_if<
|
Chris@16
|
80 is_const<Sequence>
|
Chris@16
|
81 , result_of::at_key<Sequence, Key>
|
Chris@16
|
82 >::type
|
Chris@16
|
83 at_key(Sequence& seq)
|
Chris@16
|
84 {
|
Chris@16
|
85 return result_of::at_key<Sequence, Key>::call(seq);
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 template <typename Key, typename Sequence>
|
Chris@101
|
89 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
90 inline typename result_of::at_key<Sequence const, Key>::type
|
Chris@16
|
91 at_key(Sequence const& seq)
|
Chris@16
|
92 {
|
Chris@16
|
93 return result_of::at_key<Sequence const, Key>::call(seq);
|
Chris@16
|
94 }
|
Chris@16
|
95 }}
|
Chris@16
|
96
|
Chris@16
|
97 #endif
|