]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
3 | Copyright (c) 2006 Dan Marsden | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ==============================================================================*/ | |
8 | #if !defined(FUSION_VALUE_AT_KEY_05052005_0229) | |
9 | #define FUSION_VALUE_AT_KEY_05052005_0229 | |
10 | ||
11 | #include <boost/fusion/support/config.hpp> | |
12 | #include <boost/mpl/int.hpp> | |
13 | #include <boost/mpl/empty_base.hpp> | |
14 | #include <boost/mpl/if.hpp> | |
15 | #include <boost/mpl/or.hpp> | |
16 | #include <boost/fusion/sequence/intrinsic_fwd.hpp> | |
17 | #include <boost/fusion/sequence/intrinsic/has_key.hpp> | |
18 | #include <boost/fusion/iterator/value_of_data.hpp> | |
19 | #include <boost/fusion/algorithm/query/find.hpp> | |
20 | #include <boost/fusion/support/tag_of.hpp> | |
21 | #include <boost/fusion/support/category_of.hpp> | |
22 | ||
23 | namespace boost { namespace fusion | |
24 | { | |
25 | // Special tags: | |
26 | struct sequence_facade_tag; | |
27 | struct boost_array_tag; // boost::array tag | |
28 | struct mpl_sequence_tag; // mpl sequence tag | |
29 | struct std_pair_tag; // std::pair tag | |
30 | ||
31 | namespace extension | |
32 | { | |
33 | template <typename Tag> | |
34 | struct value_at_key_impl | |
35 | { | |
36 | template <typename Seq, typename Key> | |
37 | struct apply | |
38 | : result_of::value_of_data< | |
39 | typename result_of::find<Seq, Key>::type | |
40 | > | |
41 | {}; | |
42 | }; | |
43 | ||
44 | template <> | |
45 | struct value_at_key_impl<sequence_facade_tag> | |
46 | { | |
47 | template <typename Sequence, typename Key> | |
48 | struct apply : Sequence::template value_at_key<Sequence, Key> {}; | |
49 | }; | |
50 | ||
51 | template <> | |
52 | struct value_at_key_impl<boost_array_tag>; | |
53 | ||
54 | template <> | |
55 | struct value_at_key_impl<mpl_sequence_tag>; | |
56 | ||
57 | template <> | |
58 | struct value_at_key_impl<std_pair_tag>; | |
59 | } | |
60 | ||
61 | namespace detail | |
62 | { | |
63 | template <typename Sequence, typename N, typename Tag> | |
64 | struct value_at_key_impl | |
65 | : mpl::if_< | |
66 | mpl::or_< | |
67 | typename extension::has_key_impl<Tag>::template apply<Sequence, N> | |
68 | , traits::is_unbounded<Sequence> | |
69 | > | |
70 | , typename extension::value_at_key_impl<Tag>::template apply<Sequence, N> | |
71 | , mpl::empty_base | |
72 | >::type | |
73 | {}; | |
74 | } | |
75 | ||
76 | namespace result_of | |
77 | { | |
78 | template <typename Sequence, typename N> | |
79 | struct value_at_key | |
80 | : detail::value_at_key_impl<Sequence, N, typename detail::tag_of<Sequence>::type> | |
81 | {}; | |
82 | } | |
83 | }} | |
84 | ||
85 | #endif | |
86 |