Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / fusion / sequence / intrinsic / value_at_key.hpp
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/fusion/sequence/intrinsic_fwd.hpp>
14 #include <boost/fusion/iterator/value_of_data.hpp>
15 #include <boost/fusion/algorithm/query/find.hpp>
16 #include <boost/fusion/support/tag_of.hpp>
17
18 namespace boost { namespace fusion
19 {
20     // Special tags:
21     struct sequence_facade_tag;
22     struct boost_array_tag; // boost::array tag
23     struct mpl_sequence_tag; // mpl sequence tag
24     struct std_pair_tag; // std::pair tag
25
26     namespace extension
27     {
28         template <typename Tag>
29         struct value_at_key_impl
30         {
31             template <typename Seq, typename Key>
32             struct apply
33               : result_of::value_of_data<
34                     typename result_of::find<Seq, Key>::type
35                 >
36             {};
37         };
38
39         template <>
40         struct value_at_key_impl<sequence_facade_tag>
41         {
42             template <typename Sequence, typename Key>
43             struct apply : Sequence::template value_at_key<Sequence, Key> {};
44         };
45
46         template <>
47         struct value_at_key_impl<boost_array_tag>;
48
49         template <>
50         struct value_at_key_impl<mpl_sequence_tag>;
51
52         template <>
53         struct value_at_key_impl<std_pair_tag>;
54     }
55     
56     namespace result_of
57     {
58         template <typename Sequence, typename N>
59         struct value_at_key
60             : extension::value_at_key_impl<typename detail::tag_of<Sequence>::type>::
61                 template apply<Sequence, N>
62         {};
63     }
64 }}
65
66 #endif
67