| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-04 16:17:07 +00:00
										 |  |  | // Copyright (C) 2005-2011 Daniel James
 | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | // Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
					
						
							|  |  |  | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_UNORDERED_DETAIL_EXTRACT_KEY_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_UNORDERED_DETAIL_EXTRACT_KEY_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-16 18:47:33 +00:00
										 |  |  | #include <boost/unordered/detail/table.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace boost { | 
					
						
							| 
									
										
										
										
											2011-04-16 18:47:33 +00:00
										 |  |  | namespace unordered { | 
					
						
							|  |  |  | namespace detail { | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // key extractors
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // no throw
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // 'extract_key' is called with the emplace parameters to return a
 | 
					
						
							|  |  |  |     // key if available or 'no_key' is one isn't and will need to be
 | 
					
						
							|  |  |  |     // constructed. This could be done by overloading the emplace implementation
 | 
					
						
							|  |  |  |     // for the different cases, but that's a bit tricky on compilers without
 | 
					
						
							|  |  |  |     // variadic templates.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct no_key { | 
					
						
							|  |  |  |         no_key() {} | 
					
						
							|  |  |  |         template <class T> no_key(T const&) {} | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |     template <typename Key, typename T> | 
					
						
							|  |  |  |     struct is_key { | 
					
						
							|  |  |  |         template <typename T2> | 
					
						
							|  |  |  |         static choice1::type test(T2 const&); | 
					
						
							|  |  |  |         static choice2::type test(Key const&); | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-10-06 21:06:35 +00:00
										 |  |  |         enum { value = sizeof(test(boost::unordered::detail::make<T>())) == | 
					
						
							|  |  |  |             sizeof(choice2::type) }; | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2011-09-02 08:28:19 +00:00
										 |  |  |         typedef typename boost::detail::if_true<value>:: | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |             BOOST_NESTED_TEMPLATE then<Key const&, no_key>::type type; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |     template <class ValueType> | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  |     struct set_extractor | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         typedef ValueType value_type; | 
					
						
							|  |  |  |         typedef ValueType key_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static key_type const& extract(key_type const& v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-20 23:34:38 +00:00
										 |  |  | #if BOOST_UNORDERED_USE_RV_REF
 | 
					
						
							| 
									
										
										
										
											2011-08-18 19:29:02 +00:00
										 |  |  |         static key_type const& extract(BOOST_RV_REF(key_type) v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-08-20 23:34:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-08-18 19:29:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         static no_key extract() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-08-07 08:55:28 +00:00
										 |  |  | #if defined(BOOST_UNORDERED_STD_FORWARD_MOVE)
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         template <class... Args> | 
					
						
							|  |  |  |         static no_key extract(Args const&...) | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |         template <class Arg> | 
					
						
							|  |  |  |         static no_key extract(Arg const&) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |         template <class Arg1, class Arg2> | 
					
						
							|  |  |  |         static no_key extract(Arg1 const&, Arg2 const&) | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static bool compare_mapped(value_type const&, value_type const&) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |     template <class Key, class ValueType> | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  |     struct map_extractor | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         typedef ValueType value_type; | 
					
						
							| 
									
										
										
										
											2011-10-06 08:03:25 +00:00
										 |  |  |         typedef typename boost::remove_const<Key>::type key_type; | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         static key_type const& extract(value_type const& v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v.first; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         static key_type const& extract(key_type const& v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-18 19:29:02 +00:00
										 |  |  |         // TODO: Why does this cause errors?
 | 
					
						
							|  |  |  |         //
 | 
					
						
							|  |  |  |         //static key_type const& extract(BOOST_RV_REF(key_type) v)
 | 
					
						
							|  |  |  |         //{
 | 
					
						
							|  |  |  |         //    return v;
 | 
					
						
							|  |  |  |         //}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         template <class Second> | 
					
						
							|  |  |  |         static key_type const& extract(std::pair<key_type, Second> const& v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v.first; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         template <class Second> | 
					
						
							|  |  |  |         static key_type const& extract( | 
					
						
							|  |  |  |             std::pair<key_type const, Second> const& v) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return v.first; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-09-27 19:12:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-07 08:55:28 +00:00
										 |  |  | #if defined(BOOST_UNORDERED_STD_FORWARD_MOVE)
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         template <class Arg1, class... Args> | 
					
						
							|  |  |  |         static key_type const& extract(key_type const& k, | 
					
						
							|  |  |  |             Arg1 const&, Args const&...) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return k; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         template <class... Args> | 
					
						
							|  |  |  |         static no_key extract(Args const&...) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         template <class Arg1> | 
					
						
							|  |  |  |         static key_type const& extract(key_type const& k, Arg1 const&) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return k; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static no_key extract() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         template <class Arg> | 
					
						
							|  |  |  |         static no_key extract(Arg const&) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         template <class Arg, class Arg1> | 
					
						
							|  |  |  |         static no_key extract(Arg const&, Arg1 const&) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return no_key(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  | #if defined(BOOST_UNORDERED_STD_FORWARD_MOVE)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BOOST_UNORDERED_KEY_FROM_TUPLE(namespace_)                          \
 | 
					
						
							|  |  |  |         template <typename T2>                                              \ | 
					
						
							|  |  |  |         static no_key extract(boost::unordered::piecewise_construct_t,      \ | 
					
						
							|  |  |  |                 namespace_::tuple<> const&, T2&&)                           \ | 
					
						
							|  |  |  |         {                                                                   \ | 
					
						
							|  |  |  |             return no_key();                                                \ | 
					
						
							|  |  |  |         }                                                                   \ | 
					
						
							|  |  |  |                                                                             \ | 
					
						
							|  |  |  |         template <typename T, typename T2>                                  \ | 
					
						
							| 
									
										
										
										
											2011-09-02 08:28:19 +00:00
										 |  |  |         static typename is_key<key_type, T>::type                           \ | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |             extract(boost::unordered::piecewise_construct_t,                \ | 
					
						
							|  |  |  |                 namespace_::tuple<T> const& k, T2&&)                        \ | 
					
						
							|  |  |  |         {                                                                   \ | 
					
						
							| 
									
										
										
										
											2011-09-02 08:28:19 +00:00
										 |  |  |             return typename is_key<key_type, T>::type(                      \ | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |                 namespace_::get<0>(k));                                     \ | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BOOST_UNORDERED_KEY_FROM_TUPLE(namespace_)                          \
 | 
					
						
							|  |  |  |         static no_key extract(boost::unordered::piecewise_construct_t,      \ | 
					
						
							|  |  |  |                 namespace_::tuple<> const&)                                 \ | 
					
						
							|  |  |  |         {                                                                   \ | 
					
						
							|  |  |  |             return no_key();                                                \ | 
					
						
							|  |  |  |         }                                                                   \ | 
					
						
							|  |  |  |                                                                             \ | 
					
						
							|  |  |  |         template <typename T>                                               \ | 
					
						
							| 
									
										
										
										
											2011-09-02 08:28:19 +00:00
										 |  |  |         static typename is_key<key_type, T>::type                           \ | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |             extract(boost::unordered::piecewise_construct_t,                \ | 
					
						
							|  |  |  |                 namespace_::tuple<T> const& k)                              \ | 
					
						
							|  |  |  |         {                                                                   \ | 
					
						
							| 
									
										
										
										
											2011-09-02 08:28:19 +00:00
										 |  |  |             return typename is_key<key_type, T>::type(                      \ | 
					
						
							| 
									
										
										
										
											2011-08-29 09:40:41 +00:00
										 |  |  |                 namespace_::get<0>(k));                                     \ | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BOOST_UNORDERED_KEY_FROM_TUPLE(boost) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_0X_HDR_TUPLE)
 | 
					
						
							|  |  |  | BOOST_UNORDERED_KEY_FROM_TUPLE(std) | 
					
						
							|  |  |  | #elif defined(BOOST_HAS_TR1_TUPLE)
 | 
					
						
							|  |  |  | BOOST_UNORDERED_KEY_FROM_TUPLE(std::tr1) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 08:03:26 +00:00
										 |  |  |         static bool compare_mapped(value_type const& x, value_type const& y) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return x.second == y.second; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-04-16 18:47:33 +00:00
										 |  |  | }}} | 
					
						
							| 
									
										
										
										
											2009-08-30 16:42:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 |