williamr@2
|
1 |
/* Copyright 2003-2005 Joaquín M López Muñoz.
|
williamr@2
|
2 |
* Distributed under the Boost Software License, Version 1.0.
|
williamr@2
|
3 |
* (See accompanying file LICENSE_1_0.txt or copy at
|
williamr@2
|
4 |
* http://www.boost.org/LICENSE_1_0.txt)
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* See http://www.boost.org/libs/multi_index for library home page.
|
williamr@2
|
7 |
*/
|
williamr@2
|
8 |
|
williamr@2
|
9 |
#ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ARGS_HPP
|
williamr@2
|
10 |
#define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ARGS_HPP
|
williamr@2
|
11 |
|
williamr@2
|
12 |
#if defined(_MSC_VER)&&(_MSC_VER>=1200)
|
williamr@2
|
13 |
#pragma once
|
williamr@2
|
14 |
#endif
|
williamr@2
|
15 |
|
williamr@2
|
16 |
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
|
williamr@2
|
17 |
#include <boost/functional/hash/hash.hpp>
|
williamr@2
|
18 |
#include <boost/mpl/aux_/na.hpp>
|
williamr@2
|
19 |
#include <boost/mpl/eval_if.hpp>
|
williamr@2
|
20 |
#include <boost/mpl/identity.hpp>
|
williamr@2
|
21 |
#include <boost/mpl/if.hpp>
|
williamr@2
|
22 |
#include <boost/multi_index/tag.hpp>
|
williamr@2
|
23 |
#include <boost/static_assert.hpp>
|
williamr@2
|
24 |
#include <boost/type_traits/is_same.hpp>
|
williamr@2
|
25 |
#include <functional>
|
williamr@2
|
26 |
|
williamr@2
|
27 |
namespace boost{
|
williamr@2
|
28 |
|
williamr@2
|
29 |
template<class T> struct hash; /* fwd decl. */
|
williamr@2
|
30 |
|
williamr@2
|
31 |
namespace multi_index{
|
williamr@2
|
32 |
|
williamr@2
|
33 |
namespace detail{
|
williamr@2
|
34 |
|
williamr@2
|
35 |
/* Hashed index specifiers can be instantiated in two forms:
|
williamr@2
|
36 |
*
|
williamr@2
|
37 |
* (hashed_unique|hashed_non_unique)<
|
williamr@2
|
38 |
* KeyFromValue,
|
williamr@2
|
39 |
* Hash=boost::hash<KeyFromValue::result_type>,
|
williamr@2
|
40 |
* Pred=std::equal_to<KeyFromValue::result_type> >
|
williamr@2
|
41 |
* (hashed_unique|hashed_non_unique)<
|
williamr@2
|
42 |
* TagList,
|
williamr@2
|
43 |
* KeyFromValue,
|
williamr@2
|
44 |
* Hash=boost::hash<KeyFromValue::result_type>,
|
williamr@2
|
45 |
* Pred=std::equal_to<KeyFromValue::result_type> >
|
williamr@2
|
46 |
*
|
williamr@2
|
47 |
* hashed_index_args implements the machinery to accept this
|
williamr@2
|
48 |
* argument-dependent polymorphism.
|
williamr@2
|
49 |
*/
|
williamr@2
|
50 |
|
williamr@2
|
51 |
template<typename KeyFromValue>
|
williamr@2
|
52 |
struct index_args_default_hash
|
williamr@2
|
53 |
{
|
williamr@2
|
54 |
typedef ::boost::hash<typename KeyFromValue::result_type> type;
|
williamr@2
|
55 |
};
|
williamr@2
|
56 |
|
williamr@2
|
57 |
template<typename KeyFromValue>
|
williamr@2
|
58 |
struct index_args_default_pred
|
williamr@2
|
59 |
{
|
williamr@2
|
60 |
typedef std::equal_to<typename KeyFromValue::result_type> type;
|
williamr@2
|
61 |
};
|
williamr@2
|
62 |
|
williamr@2
|
63 |
template<typename Arg1,typename Arg2,typename Arg3,typename Arg4>
|
williamr@2
|
64 |
struct hashed_index_args
|
williamr@2
|
65 |
{
|
williamr@2
|
66 |
typedef is_tag<Arg1> full_form;
|
williamr@2
|
67 |
|
williamr@2
|
68 |
typedef typename mpl::if_<
|
williamr@2
|
69 |
full_form,
|
williamr@2
|
70 |
Arg1,
|
williamr@2
|
71 |
tag< > >::type tag_list_type;
|
williamr@2
|
72 |
typedef typename mpl::if_<
|
williamr@2
|
73 |
full_form,
|
williamr@2
|
74 |
Arg2,
|
williamr@2
|
75 |
Arg1>::type key_from_value_type;
|
williamr@2
|
76 |
typedef typename mpl::if_<
|
williamr@2
|
77 |
full_form,
|
williamr@2
|
78 |
Arg3,
|
williamr@2
|
79 |
Arg2>::type supplied_hash_type;
|
williamr@2
|
80 |
typedef typename mpl::eval_if<
|
williamr@2
|
81 |
mpl::is_na<supplied_hash_type>,
|
williamr@2
|
82 |
index_args_default_hash<key_from_value_type>,
|
williamr@2
|
83 |
mpl::identity<supplied_hash_type>
|
williamr@2
|
84 |
>::type hash_type;
|
williamr@2
|
85 |
typedef typename mpl::if_<
|
williamr@2
|
86 |
full_form,
|
williamr@2
|
87 |
Arg4,
|
williamr@2
|
88 |
Arg3>::type supplied_pred_type;
|
williamr@2
|
89 |
typedef typename mpl::eval_if<
|
williamr@2
|
90 |
mpl::is_na<supplied_pred_type>,
|
williamr@2
|
91 |
index_args_default_pred<key_from_value_type>,
|
williamr@2
|
92 |
mpl::identity<supplied_pred_type>
|
williamr@2
|
93 |
>::type pred_type;
|
williamr@2
|
94 |
|
williamr@2
|
95 |
BOOST_STATIC_ASSERT(is_tag<tag_list_type>::value);
|
williamr@2
|
96 |
BOOST_STATIC_ASSERT(!mpl::is_na<key_from_value_type>::value);
|
williamr@2
|
97 |
BOOST_STATIC_ASSERT(!mpl::is_na<hash_type>::value);
|
williamr@2
|
98 |
BOOST_STATIC_ASSERT(!mpl::is_na<pred_type>::value);
|
williamr@2
|
99 |
};
|
williamr@2
|
100 |
|
williamr@2
|
101 |
} /* namespace multi_index::detail */
|
williamr@2
|
102 |
|
williamr@2
|
103 |
} /* namespace multi_index */
|
williamr@2
|
104 |
|
williamr@2
|
105 |
} /* namespace boost */
|
williamr@2
|
106 |
|
williamr@2
|
107 |
#endif
|