1 /* Copyright 2003-2005 Joaquín M López Muñoz.
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)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_NO_DUPLICATE_TAGS_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_NO_DUPLICATE_TAGS_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/mpl/fold.hpp>
18 #include <boost/mpl/set/set0.hpp>
22 namespace multi_index{
26 /* no_duplicate_tags check at compile-time that a tag list
27 * has no duplicate tags.
28 * The algorithm deserves some explanation: tags
29 * are sequentially inserted into a mpl::set if they were
30 * not already present. Due to the magic of mpl::set
31 * (mpl::has_key is contant time), this operation takes linear
32 * time, and even MSVC++ 6.5 handles it gracefully (other obvious
33 * solutions are quadratic.)
36 struct duplicate_tag_mark{};
38 struct duplicate_tag_marker
40 template <typename MplSet,typename Tag>
44 typename mpl::if_<mpl::has_key<MplSet,Tag>,duplicate_tag_mark,Tag>::type,
50 template<typename TagList>
51 struct no_duplicate_tags
53 typedef typename mpl::fold<
59 BOOST_STATIC_CONSTANT(
60 bool,value=!(mpl::has_key<aux,duplicate_tag_mark>::value));
63 /* Variant for an index list: duplication is checked
64 * across all the indices.
67 struct duplicate_tag_list_marker
69 template <typename MplSet,typename Index>
70 struct apply:mpl::fold<
71 BOOST_DEDUCED_TYPENAME Index::tag_list,
78 template<typename IndexList>
79 struct no_duplicate_tags_in_index_list
81 typedef typename mpl::fold<
84 duplicate_tag_list_marker
87 BOOST_STATIC_CONSTANT(
88 bool,value=!(mpl::has_key<aux,duplicate_tag_mark>::value));
91 } /* namespace multi_index::detail */
93 } /* namespace multi_index */
95 } /* namespace boost */