mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-02-23 10:54:54 +00:00
support hash: pair, value_holder, optional, variant, tribool
This commit is contained in:
parent
f3b405ad0f
commit
0a5f16ee81
18 changed files with 172 additions and 4 deletions
|
@ -7,6 +7,9 @@
|
|||
#include <sprout/array/array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::array<T, N> const& v) {
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
namespace sprout {
|
||||
// 20.5.3 hash support
|
||||
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<std::size_t N>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::bitset<N> const& v) {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
|
|
@ -30,6 +30,20 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last);
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last);
|
||||
|
||||
//
|
||||
// hash_values_combine
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine(std::size_t seed, Args const&... args);
|
||||
|
||||
//
|
||||
// hash_values
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values(Args const&... args);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
#include <sprout/logic/tribool/tribool_fwd.hpp>
|
||||
#include <sprout/logic/tribool/tribool.hpp>
|
||||
#include <sprout/logic/tribool/io.hpp>
|
||||
#include <sprout/logic/tribool/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_LOGIC_TRIBOOL_HPP
|
||||
|
|
28
sprout/logic/tribool/hash.hpp
Normal file
28
sprout/logic/tribool/hash.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef SPROUT_LOGIC_TRIBOOL_HASH_HPP
|
||||
#define SPROUT_LOGIC_TRIBOOL_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/logic/tribool/tribool.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::logic::indeterminate_keyword_t) {
|
||||
return sprout::logic::tribool::indeterminate_value;
|
||||
}
|
||||
namespace logic {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::logic::tribool const& v) {
|
||||
return sprout::to_hash(v.value);
|
||||
}
|
||||
} // namespace logic
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_LOGIC_TRIBOOL_HASH_HPP
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef SPROUT_LOGIC_TRIBOOL_TRIBOOL_IO_HPP
|
||||
#define SPROUT_LOGIC_TRIBOOL_TRIBOOL_IO_HPP
|
||||
#ifndef SPROUT_LOGIC_TRIBOOL_IO_HPP
|
||||
#define SPROUT_LOGIC_TRIBOOL_IO_HPP
|
||||
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
@ -206,4 +206,4 @@ namespace sprout {
|
|||
} // namespace logic
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_LOGIC_TRIBOOL_TRIBOOL_IO_HPP
|
||||
#endif // #ifndef SPROUT_LOGIC_TRIBOOL_IO_HPP
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#include <sprout/optional/nullopt.hpp>
|
||||
#include <sprout/optional/make_optional.hpp>
|
||||
#include <sprout/optional/get.hpp>
|
||||
#include <sprout/optional/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_OPTIONAL_HPP
|
||||
|
|
22
sprout/optional/hash.hpp
Normal file
22
sprout/optional/hash.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SPROUT_OPTIONAL_HASH_HPP
|
||||
#define SPROUT_OPTIONAL_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/optional/optional.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::optional<T> const& v) {
|
||||
return v.is_initialized() ? sprout::to_hash(*v)
|
||||
: 0
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_OPTIONAL_HASH_HPP
|
|
@ -7,6 +7,9 @@
|
|||
#include <sprout/pit/pit.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::pit<Container> const& v) {
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include <sprout/sub_array/sub_array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename Container>
|
||||
SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::sub_array<Container> const& v) {
|
||||
|
|
|
@ -7,5 +7,6 @@
|
|||
#include <sprout/utility/pair/tuple.hpp>
|
||||
#include <sprout/utility/pair/make_pair.hpp>
|
||||
#include <sprout/utility/pair/access.hpp>
|
||||
#include <sprout/utility/pair/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_PAIR_HPP
|
||||
|
|
20
sprout/utility/pair/hash.hpp
Normal file
20
sprout/utility/pair/hash.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_UTILITY_PAIR_HASH_HPP
|
||||
#define SPROUT_UTILITY_PAIR_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::pair<T1, T2> const& v) {
|
||||
return sprout::hash_values(v.first, v.second);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_PAIR_HASH_HPP
|
|
@ -4,5 +4,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
#include <sprout/utility/value_holder/get.hpp>
|
||||
#include <sprout/utility/value_holder/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_VALUE_HOLDER_HPP
|
||||
|
|
28
sprout/utility/value_holder/hash.hpp
Normal file
28
sprout/utility/value_holder/hash.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef SPROUT_UTILITY_VALUE_HOLDER_HASH_HPP
|
||||
#define SPROUT_UTILITY_VALUE_HOLDER_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::value_holder<T> const& v) {
|
||||
return sprout::to_hash(*v)
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::value_holder<T&> const& v) {
|
||||
return v.is_initialized() ? sprout::to_hash(*v)
|
||||
: 0
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_VALUE_HOLDER_HASH_HPP
|
|
@ -196,6 +196,9 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR mutable_or_const_pointer get_ptr() const SPROUT_NOEXCEPT {
|
||||
return get_pointer();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_initialized() const SPROUT_NOEXCEPT {
|
||||
return !!get_pointer();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/variant/io.hpp>
|
||||
#include <sprout/variant/tuple.hpp>
|
||||
#include <sprout/variant/get.hpp>
|
||||
#include <sprout/variant/hash.hpp>
|
||||
#include <sprout/variant/static_visitor.hpp>
|
||||
#include <sprout/variant/static_variant_visitor.hpp>
|
||||
#include <sprout/variant/as_visitor.hpp>
|
||||
|
|
36
sprout/variant/hash.hpp
Normal file
36
sprout/variant/hash.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef SPROUT_VARIANT_HASH_HPP
|
||||
#define SPROUT_VARIANT_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/variant/variant.hpp>
|
||||
#include <sprout/variant/static_visitor.hpp>
|
||||
#include <sprout/variant/apply_visitor.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
class variant_hash_visitor
|
||||
: public sprout::static_visitor<std::size_t>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR std::size_t operator()(T const& t) const {
|
||||
return sprout::to_hash(t);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::variant<Types...> const& v) {
|
||||
return sprout::hash_combine(
|
||||
sprout::apply_visitor(sprout::detail::variant_hash_visitor(), v),
|
||||
v.which()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VARIANT_HASH_HPP
|
Loading…
Add table
Reference in a new issue