2009-08-30 16:42:28 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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&) {}
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static no_key extract()
|
|
|
|
{
|
|
|
|
return no_key();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(BOOST_UNORDERED_STD_FORWARD)
|
|
|
|
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
|
|
|
|
2009-11-20 08:03:26 +00:00
|
|
|
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;
|
|
|
|
}
|
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-04-16 18:47:33 +00:00
|
|
|
typedef BOOST_DEDUCED_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-08-30 16:42:28 +00:00
|
|
|
#if defined(BOOST_UNORDERED_STD_FORWARD)
|
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
|
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
|
|
|
|
|
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
|