From 2b9251069f3dcf8d9acb9ec9691404b5dc312eb8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 17 Oct 2021 02:40:29 +0300 Subject: [PATCH] Move std::tuple support to detail/hash_tuple.hpp --- .../container_hash/detail/hash_tuple.hpp | 132 ++++++++++++++++++ include/boost/container_hash/extensions.hpp | 120 +--------------- include/boost/container_hash/hash.hpp | 1 + 3 files changed, 136 insertions(+), 117 deletions(-) create mode 100644 include/boost/container_hash/detail/hash_tuple.hpp diff --git a/include/boost/container_hash/detail/hash_tuple.hpp b/include/boost/container_hash/detail/hash_tuple.hpp new file mode 100644 index 0000000..7260716 --- /dev/null +++ b/include/boost/container_hash/detail/hash_tuple.hpp @@ -0,0 +1,132 @@ +// Copyright 2005-2009 Daniel James. +// Copyright 2021 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP +#define BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP + +#include +#include + +#if defined(BOOST_NO_CXX11_HDR_TUPLE) + +// no support + +#else + +#include + +namespace boost +{ +namespace hash_detail +{ + +template +inline typename boost::enable_if_c<(I == std::tuple_size::value), + void>::type + hash_combine_tuple(std::size_t&, T const&) +{ +} + +template +inline typename boost::enable_if_c<(I < std::tuple_size::value), + void>::type + hash_combine_tuple(std::size_t& seed, T const& v) +{ + boost::hash_combine(seed, std::get(v)); + boost::hash_detail::hash_combine_tuple(seed, v); +} + +template +inline std::size_t hash_tuple(T const& v) +{ + std::size_t seed = 0; + boost::hash_detail::hash_combine_tuple<0>(seed, v); + return seed; +} + +} // namespace hash_detail + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +#else + +inline std::size_t hash_value(std::tuple<> const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +template +inline std::size_t hash_value(std::tuple const& v) +{ + return boost::hash_detail::hash_tuple(v); +} + +#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +} // namespace boost + +#endif // #if defined(BOOST_NO_CXX11_HDR_TUPLE) + +#endif // #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP diff --git a/include/boost/container_hash/extensions.hpp b/include/boost/container_hash/extensions.hpp index cc1a421..469cfbb 100644 --- a/include/boost/container_hash/extensions.hpp +++ b/include/boost/container_hash/extensions.hpp @@ -10,128 +10,14 @@ // This implements the extensions to the standard. // It's undocumented, so you shouldn't use it.... -#if !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP) +#ifndef BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP #define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP -#include -#if defined(BOOST_HAS_PRAGMA_ONCE) -#pragma once -#endif - #include -#include -#include - -#if !defined(BOOST_NO_CXX11_HDR_TUPLE) -# include -#endif +#include namespace boost { -#if !defined(BOOST_NO_CXX11_HDR_TUPLE) - namespace hash_detail { - template - inline typename boost::enable_if_c<(I == std::tuple_size::value), - void>::type - hash_combine_tuple(std::size_t&, T const&) - { - } - - template - inline typename boost::enable_if_c<(I < std::tuple_size::value), - void>::type - hash_combine_tuple(std::size_t& seed, T const& v) - { - boost::hash_combine(seed, std::get(v)); - boost::hash_detail::hash_combine_tuple(seed, v); - } - - template - inline std::size_t hash_tuple(T const& v) - { - std::size_t seed = 0; - boost::hash_detail::hash_combine_tuple<0>(seed, v); - return seed; - } - } - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } -#else - - inline std::size_t hash_value(std::tuple<> const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - - template - inline std::size_t hash_value(std::tuple const& v) - { - return boost::hash_detail::hash_tuple(v); - } - -#endif - -#endif - // // boost::hash // @@ -146,4 +32,4 @@ namespace boost }; } -#endif +#endif // #ifndef BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index c4ba130..7f86cb5 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include