2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2011-10-29 02:05:42 +00:00
|
|
|
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_HPP
|
|
|
|
#define SPROUT_FUNCTIONAL_HASH_HASH_HPP
|
2011-10-12 20:28:33 +00:00
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2011-10-12 20:28:33 +00:00
|
|
|
#include <sprout/functional/hash/hash_fwd.hpp>
|
2013-02-04 09:42:39 +00:00
|
|
|
#include <sprout/functional/hash/to_hash.hpp>
|
2013-02-07 14:39:57 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2011-10-12 20:28:33 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
2011-10-29 02:05:42 +00:00
|
|
|
//
|
|
|
|
// hash
|
|
|
|
//
|
2013-02-07 16:14:42 +00:00
|
|
|
template<typename T = void>
|
2011-10-29 02:05:42 +00:00
|
|
|
struct hash {
|
|
|
|
public:
|
|
|
|
typedef T argument_type;
|
|
|
|
typedef std::size_t result_type;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR std::size_t operator()(T const& v) const {
|
2011-10-29 03:02:21 +00:00
|
|
|
return sprout::to_hash(v);
|
2011-10-29 02:05:42 +00:00
|
|
|
}
|
|
|
|
};
|
2012-06-20 15:57:27 +00:00
|
|
|
template<typename T>
|
|
|
|
struct hash<T const>
|
|
|
|
: public sprout::hash<T>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct hash<T volatile>
|
|
|
|
: public sprout::hash<T>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct hash<T const volatile>
|
|
|
|
: public sprout::hash<T>
|
|
|
|
{};
|
2013-02-07 14:39:57 +00:00
|
|
|
template<>
|
|
|
|
struct hash<void> {
|
|
|
|
public:
|
|
|
|
typedef std::size_t result_type;
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
SPROUT_CONSTEXPR std::size_t
|
|
|
|
operator()(T&& v)
|
2014-02-22 07:32:51 +00:00
|
|
|
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::to_hash(SPROUT_FORWARD(T, v))))
|
2013-02-07 14:39:57 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::to_hash(SPROUT_FORWARD(T, v));
|
2013-02-07 14:39:57 +00:00
|
|
|
}
|
|
|
|
};
|
2011-10-29 02:05:42 +00:00
|
|
|
|
2011-10-12 20:28:33 +00:00
|
|
|
#define SPROUT_HASH_SPECIALIZE(type) \
|
|
|
|
template<> \
|
|
|
|
struct hash<type> { \
|
|
|
|
public: \
|
|
|
|
typedef type argument_type; \
|
|
|
|
typedef std::size_t result_type; \
|
|
|
|
public: \
|
|
|
|
SPROUT_CONSTEXPR std::size_t operator()(type v) const { \
|
2012-06-20 15:57:27 +00:00
|
|
|
return sprout::to_hash(v); \
|
2011-10-12 20:28:33 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define SPROUT_HASH_SPECIALIZE_REF(type) \
|
|
|
|
template<> \
|
|
|
|
struct hash<type> { \
|
|
|
|
public: \
|
|
|
|
typedef type argument_type; \
|
|
|
|
typedef std::size_t result_type; \
|
|
|
|
public: \
|
|
|
|
SPROUT_CONSTEXPR std::size_t operator()(type const& v) const { \
|
2012-06-20 15:57:27 +00:00
|
|
|
return sprout::to_hash(v); \
|
2011-10-12 20:28:33 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
SPROUT_HASH_SPECIALIZE(bool);
|
|
|
|
SPROUT_HASH_SPECIALIZE(char);
|
|
|
|
SPROUT_HASH_SPECIALIZE(signed char);
|
|
|
|
SPROUT_HASH_SPECIALIZE(unsigned char);
|
2012-04-09 16:38:55 +00:00
|
|
|
SPROUT_HASH_SPECIALIZE(char16_t);
|
|
|
|
SPROUT_HASH_SPECIALIZE(char32_t);
|
|
|
|
SPROUT_HASH_SPECIALIZE(wchar_t);
|
2011-10-12 20:28:33 +00:00
|
|
|
SPROUT_HASH_SPECIALIZE(short);
|
|
|
|
SPROUT_HASH_SPECIALIZE(unsigned short);
|
|
|
|
SPROUT_HASH_SPECIALIZE(int);
|
|
|
|
SPROUT_HASH_SPECIALIZE(unsigned int);
|
|
|
|
SPROUT_HASH_SPECIALIZE(long);
|
|
|
|
SPROUT_HASH_SPECIALIZE(unsigned long);
|
|
|
|
SPROUT_HASH_SPECIALIZE(long long);
|
|
|
|
SPROUT_HASH_SPECIALIZE(unsigned long long);
|
|
|
|
|
|
|
|
#undef SPROUT_HASH_SPECIALIZE
|
|
|
|
#undef SPROUT_HASH_SPECIALIZE_REF
|
|
|
|
|
2011-10-29 02:05:42 +00:00
|
|
|
template<typename T>
|
2012-06-20 15:57:27 +00:00
|
|
|
struct hash<T*> {
|
2011-10-29 03:02:21 +00:00
|
|
|
public:
|
2012-06-20 15:57:27 +00:00
|
|
|
typedef T* argument_type;
|
2011-10-29 03:02:21 +00:00
|
|
|
typedef std::size_t result_type;
|
|
|
|
public:
|
2012-06-20 15:57:27 +00:00
|
|
|
std::size_t operator()(T* v) const {
|
2011-10-29 03:02:21 +00:00
|
|
|
return sprout::to_hash(v);
|
|
|
|
}
|
|
|
|
};
|
2013-01-10 17:55:19 +00:00
|
|
|
} // namespace sprout
|
2011-10-12 20:28:33 +00:00
|
|
|
|
2011-10-29 02:05:42 +00:00
|
|
|
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_HPP
|