source: NonGTP/Boost/boost/multi_index/detail/hash_index_args.hpp @ 857

Revision 857, 3.2 KB checked in by igarcia, 18 years ago (diff)
Line 
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)
5 *
6 * See http://www.boost.org/libs/multi_index for library home page.
7 */
8
9#ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ARGS_HPP
10#define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ARGS_HPP
11
12#if defined(_MSC_VER)&&(_MSC_VER>=1200)
13#pragma once
14#endif
15
16#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17#include <boost/functional/hash/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>
25#include <functional>
26
27namespace boost{
28
29template<class T> struct hash; /* fwd decl. */
30
31namespace multi_index{
32
33namespace detail{
34
35/* Hashed index specifiers can be instantiated in two forms:
36 *
37 *   (hashed_unique|hashed_non_unique)<
38 *     KeyFromValue,
39 *     Hash=boost::hash<KeyFromValue::result_type>,
40 *     Pred=std::equal_to<KeyFromValue::result_type> >
41 *   (hashed_unique|hashed_non_unique)<
42 *     TagList,
43 *     KeyFromValue,
44 *     Hash=boost::hash<KeyFromValue::result_type>,
45 *     Pred=std::equal_to<KeyFromValue::result_type> >
46 *
47 * hashed_index_args implements the machinery to accept this
48 * argument-dependent polymorphism.
49 */
50
51template<typename KeyFromValue>
52struct index_args_default_hash
53{
54  typedef ::boost::hash<typename KeyFromValue::result_type> type;
55};
56
57template<typename KeyFromValue>
58struct index_args_default_pred
59{
60  typedef std::equal_to<typename KeyFromValue::result_type> type;
61};
62
63template<typename Arg1,typename Arg2,typename Arg3,typename Arg4>
64struct hashed_index_args
65{
66  typedef is_tag<Arg1> full_form;
67
68  typedef typename mpl::if_<
69    full_form,
70    Arg1,
71    tag< > >::type                                   tag_list_type;
72  typedef typename mpl::if_<
73    full_form,
74    Arg2,
75    Arg1>::type                                      key_from_value_type;
76  typedef typename mpl::if_<
77    full_form,
78    Arg3,
79    Arg2>::type                                      supplied_hash_type;
80  typedef typename mpl::eval_if<
81    mpl::is_na<supplied_hash_type>,
82    index_args_default_hash<key_from_value_type>,
83    mpl::identity<supplied_hash_type>
84  >::type                                            hash_type;
85  typedef typename mpl::if_<
86    full_form,
87    Arg4,
88    Arg3>::type                                      supplied_pred_type;
89  typedef typename mpl::eval_if<
90    mpl::is_na<supplied_pred_type>,
91    index_args_default_pred<key_from_value_type>,
92    mpl::identity<supplied_pred_type>
93  >::type                                            pred_type;
94
95  BOOST_STATIC_ASSERT(is_tag<tag_list_type>::value);
96  BOOST_STATIC_ASSERT(!mpl::is_na<key_from_value_type>::value);
97  BOOST_STATIC_ASSERT(!mpl::is_na<hash_type>::value);
98  BOOST_STATIC_ASSERT(!mpl::is_na<pred_type>::value);
99};
100
101} /* namespace multi_index::detail */
102
103} /* namespace multi_index */
104
105} /* namespace boost */
106
107#endif
Note: See TracBrowser for help on using the repository browser.