1 /* Copyright 2003-2007 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_HASH_INDEX_ARGS_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ARGS_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/functional/hash.hpp>
18 #include <boost/mpl/aux_/na.hpp>
19 #include <boost/mpl/eval_if.hpp>
20 #include <boost/mpl/identity.hpp>
21 #include <boost/mpl/if.hpp>
22 #include <boost/multi_index/tag.hpp>
23 #include <boost/static_assert.hpp>
24 #include <boost/type_traits/is_same.hpp>
29 namespace multi_index{
33 /* Hashed index specifiers can be instantiated in two forms:
35 * (hashed_unique|hashed_non_unique)<
37 * Hash=boost::hash<KeyFromValue::result_type>,
38 * Pred=std::equal_to<KeyFromValue::result_type> >
39 * (hashed_unique|hashed_non_unique)<
42 * Hash=boost::hash<KeyFromValue::result_type>,
43 * Pred=std::equal_to<KeyFromValue::result_type> >
45 * hashed_index_args implements the machinery to accept this
46 * argument-dependent polymorphism.
49 template<typename KeyFromValue>
50 struct index_args_default_hash
52 typedef ::boost::hash<typename KeyFromValue::result_type> type;
55 template<typename KeyFromValue>
56 struct index_args_default_pred
58 typedef std::equal_to<typename KeyFromValue::result_type> type;
61 template<typename Arg1,typename Arg2,typename Arg3,typename Arg4>
62 struct hashed_index_args
64 typedef is_tag<Arg1> full_form;
66 typedef typename mpl::if_<
69 tag< > >::type tag_list_type;
70 typedef typename mpl::if_<
73 Arg1>::type key_from_value_type;
74 typedef typename mpl::if_<
77 Arg2>::type supplied_hash_type;
78 typedef typename mpl::eval_if<
79 mpl::is_na<supplied_hash_type>,
80 index_args_default_hash<key_from_value_type>,
81 mpl::identity<supplied_hash_type>
83 typedef typename mpl::if_<
86 Arg3>::type supplied_pred_type;
87 typedef typename mpl::eval_if<
88 mpl::is_na<supplied_pred_type>,
89 index_args_default_pred<key_from_value_type>,
90 mpl::identity<supplied_pred_type>
93 BOOST_STATIC_ASSERT(is_tag<tag_list_type>::value);
94 BOOST_STATIC_ASSERT(!mpl::is_na<key_from_value_type>::value);
95 BOOST_STATIC_ASSERT(!mpl::is_na<hash_type>::value);
96 BOOST_STATIC_ASSERT(!mpl::is_na<pred_type>::value);
99 } /* namespace multi_index::detail */
101 } /* namespace multi_index */
103 } /* namespace boost */