forked from boostorg/unordered
Merged revisions 56441,56461,56468,56557-56562 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r56441 | danieljames | 2009-09-27 20:12:04 +0100 (Sun, 27 Sep 2009) | 1 line Try supporting reference parameters in pairs. Probably not required. ........ r56461 | danieljames | 2009-09-29 00:06:03 +0100 (Tue, 29 Sep 2009) | 1 line Remove the optimization for std::pair with a key reference. It'll be too much hassle to get a very unusual use case to work on all compilers. ........ r56468 | danieljames | 2009-09-29 08:46:44 +0100 (Tue, 29 Sep 2009) | 1 line Just remove the test since the test itself doesn't work on most compilers. ........ r56557 | danieljames | 2009-10-03 17:40:26 +0100 (Sat, 03 Oct 2009) | 1 line Fix the iterator category. ........ r56558 | danieljames | 2009-10-03 17:40:53 +0100 (Sat, 03 Oct 2009) | 2 lines Update reference docs to latest version of draft standard and fill in some missing details. ........ r56559 | danieljames | 2009-10-03 17:41:11 +0100 (Sat, 03 Oct 2009) | 1 line Stricter insert exception tests. ........ r56560 | danieljames | 2009-10-03 17:41:32 +0100 (Sat, 03 Oct 2009) | 1 line Insert using initializer lists. ........ r56561 | danieljames | 2009-10-03 17:42:00 +0100 (Sat, 03 Oct 2009) | 1 line Update the unordered rationale. ........ r56562 | danieljames | 2009-10-03 17:42:20 +0100 (Sat, 03 Oct 2009) | 1 line Make sure inserting from a range of types other than the value type is better tested. ........ [SVN r56700]
157 lines
4.0 KiB
C++
157 lines
4.0 KiB
C++
|
|
// Copyright (C) 2005-2009 Daniel James
|
|
// 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
|
|
|
|
#include <boost/config.hpp>
|
|
#include <boost/type_traits/remove_const.hpp>
|
|
#include <boost/unordered/detail/fwd.hpp>
|
|
|
|
namespace boost {
|
|
namespace unordered_detail {
|
|
|
|
// 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&) {}
|
|
};
|
|
|
|
struct set_extractor
|
|
{
|
|
template <class ValueType>
|
|
struct apply
|
|
{
|
|
typedef ValueType value_type;
|
|
typedef ValueType key_type;
|
|
|
|
static key_type const& extract(key_type const& v)
|
|
{
|
|
return v;
|
|
}
|
|
|
|
static no_key extract()
|
|
{
|
|
return no_key();
|
|
}
|
|
|
|
#if defined(BOOST_UNORDERED_STD_FORWARD)
|
|
template <class... Args>
|
|
static no_key extract(Args const&...)
|
|
{
|
|
return no_key();
|
|
}
|
|
|
|
#else
|
|
template <class Arg>
|
|
static no_key extract(Arg const&)
|
|
{
|
|
return no_key();
|
|
}
|
|
|
|
template <class Arg>
|
|
static no_key extract(Arg const&, Arg const&)
|
|
{
|
|
return no_key();
|
|
}
|
|
#endif
|
|
|
|
static bool compare_mapped(value_type const&, value_type const&)
|
|
{
|
|
return true;
|
|
}
|
|
};
|
|
};
|
|
|
|
struct map_extractor
|
|
{
|
|
template <class ValueType>
|
|
struct apply
|
|
{
|
|
typedef ValueType value_type;
|
|
typedef BOOST_DEDUCED_TYPENAME
|
|
remove_const<BOOST_DEDUCED_TYPENAME ValueType::first_type>::type
|
|
key_type;
|
|
|
|
static key_type const& extract(value_type const& v)
|
|
{
|
|
return v.first;
|
|
}
|
|
|
|
static key_type const& extract(key_type const& v)
|
|
{
|
|
return v;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
#if defined(BOOST_UNORDERED_STD_FORWARD)
|
|
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();
|
|
}
|
|
#else
|
|
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();
|
|
}
|
|
#endif
|
|
|
|
static bool compare_mapped(value_type const& x, value_type const& y)
|
|
{
|
|
return x.second == y.second;
|
|
}
|
|
};
|
|
};
|
|
}}
|
|
|
|
#endif
|