1 | |
---|
2 | // Copyright (C) 2005-2009 Daniel James |
---|
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
---|
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | #ifndef BOOST_UNORDERED_DETAIL_EXTRACT_KEY_HPP_INCLUDED |
---|
7 | #define BOOST_UNORDERED_DETAIL_EXTRACT_KEY_HPP_INCLUDED |
---|
8 | |
---|
9 | #include <boost/config.hpp> |
---|
10 | #include <boost/type_traits/remove_const.hpp> |
---|
11 | #include <boost/unordered/detail/fwd.hpp> |
---|
12 | |
---|
13 | namespace boost { |
---|
14 | namespace unordered_detail { |
---|
15 | |
---|
16 | // key extractors |
---|
17 | // |
---|
18 | // no throw |
---|
19 | // |
---|
20 | // 'extract_key' is called with the emplace parameters to return a |
---|
21 | // key if available or 'no_key' is one isn't and will need to be |
---|
22 | // constructed. This could be done by overloading the emplace implementation |
---|
23 | // for the different cases, but that's a bit tricky on compilers without |
---|
24 | // variadic templates. |
---|
25 | |
---|
26 | struct no_key { |
---|
27 | no_key() {} |
---|
28 | template <class T> no_key(T const&) {} |
---|
29 | }; |
---|
30 | |
---|
31 | template <class ValueType> |
---|
32 | struct set_extractor |
---|
33 | { |
---|
34 | typedef ValueType value_type; |
---|
35 | typedef ValueType key_type; |
---|
36 | |
---|
37 | static key_type const& extract(key_type const& v) |
---|
38 | { |
---|
39 | return v; |
---|
40 | } |
---|
41 | |
---|
42 | static no_key extract() |
---|
43 | { |
---|
44 | return no_key(); |
---|
45 | } |
---|
46 | |
---|
47 | #if defined(BOOST_UNORDERED_STD_FORWARD) |
---|
48 | template <class... Args> |
---|
49 | static no_key extract(Args const&...) |
---|
50 | { |
---|
51 | return no_key(); |
---|
52 | } |
---|
53 | |
---|
54 | #else |
---|
55 | template <class Arg> |
---|
56 | static no_key extract(Arg const&) |
---|
57 | { |
---|
58 | return no_key(); |
---|
59 | } |
---|
60 | |
---|
61 | template <class Arg> |
---|
62 | static no_key extract(Arg const&, Arg const&) |
---|
63 | { |
---|
64 | return no_key(); |
---|
65 | } |
---|
66 | #endif |
---|
67 | |
---|
68 | static bool compare_mapped(value_type const&, value_type const&) |
---|
69 | { |
---|
70 | return true; |
---|
71 | } |
---|
72 | }; |
---|
73 | |
---|
74 | template <class Key, class ValueType> |
---|
75 | struct map_extractor |
---|
76 | { |
---|
77 | typedef ValueType value_type; |
---|
78 | typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Key>::type key_type; |
---|
79 | |
---|
80 | static key_type const& extract(value_type const& v) |
---|
81 | { |
---|
82 | return v.first; |
---|
83 | } |
---|
84 | |
---|
85 | static key_type const& extract(key_type const& v) |
---|
86 | { |
---|
87 | return v; |
---|
88 | } |
---|
89 | |
---|
90 | template <class Second> |
---|
91 | static key_type const& extract(std::pair<key_type, Second> const& v) |
---|
92 | { |
---|
93 | return v.first; |
---|
94 | } |
---|
95 | |
---|
96 | template <class Second> |
---|
97 | static key_type const& extract( |
---|
98 | std::pair<key_type const, Second> const& v) |
---|
99 | { |
---|
100 | return v.first; |
---|
101 | } |
---|
102 | |
---|
103 | #if defined(BOOST_UNORDERED_STD_FORWARD) |
---|
104 | template <class Arg1, class... Args> |
---|
105 | static key_type const& extract(key_type const& k, |
---|
106 | Arg1 const&, Args const&...) |
---|
107 | { |
---|
108 | return k; |
---|
109 | } |
---|
110 | |
---|
111 | template <class... Args> |
---|
112 | static no_key extract(Args const&...) |
---|
113 | { |
---|
114 | return no_key(); |
---|
115 | } |
---|
116 | #else |
---|
117 | template <class Arg1> |
---|
118 | static key_type const& extract(key_type const& k, Arg1 const&) |
---|
119 | { |
---|
120 | return k; |
---|
121 | } |
---|
122 | |
---|
123 | static no_key extract() |
---|
124 | { |
---|
125 | return no_key(); |
---|
126 | } |
---|
127 | |
---|
128 | template <class Arg> |
---|
129 | static no_key extract(Arg const&) |
---|
130 | { |
---|
131 | return no_key(); |
---|
132 | } |
---|
133 | |
---|
134 | template <class Arg, class Arg1> |
---|
135 | static no_key extract(Arg const&, Arg1 const&) |
---|
136 | { |
---|
137 | return no_key(); |
---|
138 | } |
---|
139 | #endif |
---|
140 | |
---|
141 | static bool compare_mapped(value_type const& x, value_type const& y) |
---|
142 | { |
---|
143 | return x.second == y.second; |
---|
144 | } |
---|
145 | }; |
---|
146 | }} |
---|
147 | |
---|
148 | #endif |
---|