]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_TAG_HPP | |
10 | #define BOOST_MULTI_INDEX_TAG_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/multi_index/detail/no_duplicate_tags.hpp> | |
18 | #include <boost/mpl/identity.hpp> | |
19 | #include <boost/mpl/transform.hpp> | |
20 | #include <boost/mpl/vector.hpp> | |
21 | #include <boost/preprocessor/facilities/intercept.hpp> | |
22 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
23 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
24 | #include <boost/static_assert.hpp> | |
25 | #include <boost/type_traits/is_base_and_derived.hpp> | |
26 | ||
27 | /* A wrapper of mpl::vector used to hide MPL from the user. | |
28 | * tag contains types used as tag names for indices in get() functions. | |
29 | */ | |
30 | ||
31 | /* This user_definable macro limits the number of elements of a tag; | |
32 | * useful for shortening resulting symbol names (MSVC++ 6.0, for instance, | |
33 | * has problems coping with very long symbol names.) | |
34 | */ | |
35 | ||
36 | #if !defined(BOOST_MULTI_INDEX_LIMIT_TAG_SIZE) | |
37 | #define BOOST_MULTI_INDEX_LIMIT_TAG_SIZE BOOST_MPL_LIMIT_VECTOR_SIZE | |
38 | #endif | |
39 | ||
40 | #if BOOST_MULTI_INDEX_LIMIT_TAG_SIZE<BOOST_MPL_LIMIT_VECTOR_SIZE | |
41 | #define BOOST_MULTI_INDEX_TAG_SIZE BOOST_MULTI_INDEX_LIMIT_TAG_SIZE | |
42 | #else | |
43 | #define BOOST_MULTI_INDEX_TAG_SIZE BOOST_MPL_LIMIT_VECTOR_SIZE | |
44 | #endif | |
45 | ||
46 | namespace boost{ | |
47 | ||
48 | namespace multi_index{ | |
49 | ||
50 | namespace detail{ | |
51 | ||
52 | struct tag_marker{}; | |
53 | ||
54 | template<typename T> | |
55 | struct is_tag | |
56 | { | |
57 | BOOST_STATIC_CONSTANT(bool,value=(is_base_and_derived<tag_marker,T>::value)); | |
58 | }; | |
59 | ||
60 | } /* namespace multi_index::detail */ | |
61 | ||
62 | template< | |
63 | BOOST_PP_ENUM_BINARY_PARAMS( | |
64 | BOOST_MULTI_INDEX_TAG_SIZE, | |
65 | typename T, | |
66 | =mpl::na BOOST_PP_INTERCEPT) | |
67 | > | |
68 | struct tag:private detail::tag_marker | |
69 | { | |
70 | /* The mpl::transform pass produces shorter symbols (without | |
71 | * trailing mpl::na's.) | |
72 | */ | |
73 | ||
74 | typedef typename mpl::transform< | |
75 | mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_MULTI_INDEX_TAG_SIZE,T)>, | |
76 | mpl::identity<mpl::_1> | |
77 | >::type type; | |
78 | ||
79 | BOOST_STATIC_ASSERT(detail::no_duplicate_tags<type>::value); | |
80 | }; | |
81 | ||
82 | } /* namespace multi_index */ | |
83 | ||
84 | } /* namespace boost */ | |
85 | ||
86 | #undef BOOST_MULTI_INDEX_TAG_SIZE | |
87 | ||
88 | #endif |