PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/fusion/sequence/intrinsic/at_key.hpp

http://hadesmem.googlecode.com/
C++ Header | 92 lines | 72 code | 12 blank | 8 comment | 0 complexity | 646de4de31e25c0f7596f6d31692bdb4 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2006 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(BOOST_FUSION_AT_KEY_20060304_1755)
 9#define BOOST_FUSION_AT_KEY_20060304_1755
10
11#include <boost/type_traits/is_const.hpp>
12#include <boost/fusion/algorithm/query/find.hpp>
13#include <boost/fusion/iterator/deref_data.hpp>
14#include <boost/fusion/support/tag_of.hpp>
15#include <boost/fusion/support/detail/access.hpp>
16
17namespace boost { namespace fusion
18{
19    // Special tags:
20    struct sequence_facade_tag;
21    struct boost_array_tag; // boost::array tag
22    struct mpl_sequence_tag; // mpl sequence tag
23    struct std_pair_tag; // std::pair tag
24
25    namespace extension
26    {
27        template <typename Tag>
28        struct at_key_impl
29        {
30            template <typename Seq, typename Key>
31            struct apply
32            {
33                typedef typename
34                    result_of::deref_data<
35                        typename result_of::find<Seq, Key>::type
36                    >::type
37                type;
38
39                static type
40                call(Seq& seq)
41                {
42                    return fusion::deref_data(fusion::find<Key>(seq));
43                }
44            };
45        };
46
47        template <>
48        struct at_key_impl<sequence_facade_tag>
49        {
50            template <typename Sequence, typename Key>
51            struct apply : Sequence::template at_key_impl<Sequence, Key> {};
52        };
53
54        template <>
55        struct at_key_impl<boost_array_tag>;
56
57        template <>
58        struct at_key_impl<mpl_sequence_tag>;
59
60        template <>
61        struct at_key_impl<std_pair_tag>;
62    }
63
64    namespace result_of
65    {
66        template <typename Sequence, typename Key>
67        struct at_key
68            : extension::at_key_impl<typename detail::tag_of<Sequence>::type>::
69                template apply<Sequence, Key>
70        {};
71    }
72
73    template <typename Key, typename Sequence>
74    inline typename 
75        lazy_disable_if<
76            is_const<Sequence>
77          , result_of::at_key<Sequence, Key>
78        >::type
79    at_key(Sequence& seq)
80    {
81        return result_of::at_key<Sequence, Key>::call(seq);
82    }
83
84    template <typename Key, typename Sequence>
85    inline typename result_of::at_key<Sequence const, Key>::type
86    at_key(Sequence const& seq)
87    {
88        return result_of::at_key<Sequence const, Key>::call(seq);
89    }
90}}
91
92#endif