1 | /* Copyright 2003-2013 Joaquin M Lopez Munoz. |
2 | * Distributed under the Boost Software License, Version 1.0. |
3 | * (See accompanying file LICENSE_1_0.txt or copy at |
4 | * http://www.boost.org/LICENSE_1_0.txt) |
5 | * |
6 | * See http://www.boost.org/libs/multi_index for library home page. |
7 | */ |
8 | |
9 | #ifndef BOOST_MULTI_INDEX_DETAIL_BASE_TYPE_HPP |
10 | #define BOOST_MULTI_INDEX_DETAIL_BASE_TYPE_HPP |
11 | |
12 | #if defined(_MSC_VER) |
13 | #pragma once |
14 | #endif |
15 | |
16 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
17 | #include <boost/detail/workaround.hpp> |
18 | #include <boost/mpl/at.hpp> |
19 | #include <boost/mpl/apply.hpp> |
20 | #include <boost/mpl/size.hpp> |
21 | #include <boost/multi_index/detail/index_base.hpp> |
22 | #include <boost/multi_index/detail/is_index_list.hpp> |
23 | #include <boost/static_assert.hpp> |
24 | |
25 | namespace boost{ |
26 | |
27 | namespace multi_index{ |
28 | |
29 | namespace detail{ |
30 | |
31 | /* MPL machinery to construct a linear hierarchy of indices out of |
32 | * a index list. |
33 | */ |
34 | |
35 | struct index_applier |
36 | { |
37 | template<typename IndexSpecifierMeta,typename SuperMeta> |
38 | struct apply |
39 | { |
40 | typedef typename IndexSpecifierMeta::type index_specifier; |
41 | typedef typename index_specifier:: |
42 | BOOST_NESTED_TEMPLATE index_class<SuperMeta>::type type; |
43 | }; |
44 | }; |
45 | |
46 | template<int N,typename Value,typename IndexSpecifierList,typename Allocator> |
47 | struct nth_layer |
48 | { |
49 | BOOST_STATIC_CONSTANT(int,length=mpl::size<IndexSpecifierList>::value); |
50 | |
51 | typedef typename mpl::eval_if_c< |
52 | N==length, |
53 | mpl::identity<index_base<Value,IndexSpecifierList,Allocator> >, |
54 | mpl::apply2< |
55 | index_applier, |
56 | mpl::at_c<IndexSpecifierList,N>, |
57 | nth_layer<N+1,Value,IndexSpecifierList,Allocator> |
58 | > |
59 | >::type type; |
60 | }; |
61 | |
62 | template<typename Value,typename IndexSpecifierList,typename Allocator> |
63 | struct multi_index_base_type:nth_layer<0,Value,IndexSpecifierList,Allocator> |
64 | { |
65 | BOOST_STATIC_ASSERT(detail::is_index_list<IndexSpecifierList>::value); |
66 | }; |
67 | |
68 | } /* namespace multi_index::detail */ |
69 | |
70 | } /* namespace multi_index */ |
71 | |
72 | } /* namespace boost */ |
73 | |
74 | #endif |
75 | |