From 6ad6bc005c33dbf677c2a413ff435b7219edbc4e Mon Sep 17 00:00:00 2001 From: Dimitrij Mijoski Date: Fri, 20 Apr 2018 13:42:07 +0200 Subject: [PATCH 1/4] Implement boost hash for string_view --- .travis.yml | 1 + appveyor.yml | 1 + include/boost/utility/string_view.hpp | 5 +++++ test/string_view_test1.cpp | 9 +++++++++ 4 files changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index ab048db..7448bf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -192,6 +192,7 @@ install: - git submodule update --init libs/static_assert - git submodule update --init libs/throw_exception - git submodule update --init libs/type_traits + - git submodule update --init libs/container_hash - cp -r $TRAVIS_BUILD_DIR/* libs/utility - ./bootstrap.sh - ./b2 headers diff --git a/appveyor.yml b/appveyor.yml index 77623f0..cb0cf9f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,7 @@ install: - git submodule update --init libs/static_assert - git submodule update --init libs/throw_exception - git submodule update --init libs/type_traits + - git submodule update --init libs/container_hash - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\utility - cmd /c bootstrap - b2 -d0 headers diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 44efda9..0faa8f0 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -690,6 +691,10 @@ namespace boost { } #endif + template + std::size_t hash_value(basic_string_view s) { + return boost::hash_range(s.begin(), s.end()); + } } #if 0 diff --git a/test/string_view_test1.cpp b/test/string_view_test1.cpp index 9b70a7e..90aec4e 100644 --- a/test/string_view_test1.cpp +++ b/test/string_view_test1.cpp @@ -85,6 +85,14 @@ void test_remove ( const std::string &str ) { } } +void test_hash(const std::string& str) { + string_view ref = str; + BOOST_TEST(boost::hash_value(ref) == boost::hash_value(str)); + boost::hash hstr; + boost::hash hsv; + BOOST_TEST(hsv(ref) == hstr(str)); + } + const char *test_strings [] = { "", "1", @@ -102,6 +110,7 @@ int main() test_substr ( *p ); test_remove ( *p ); null_tests ( *p ); + test_hash( *p ); p++; } From 473be2e4c1987976d3e00617fa0caa24ca67f554 Mon Sep 17 00:00:00 2001 From: Dimitrij Mijoski Date: Fri, 20 Apr 2018 13:58:12 +0200 Subject: [PATCH 2/4] Boost integer is dependency of boost hash. --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7448bf9..1c6dbdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -193,6 +193,7 @@ install: - git submodule update --init libs/throw_exception - git submodule update --init libs/type_traits - git submodule update --init libs/container_hash + - git submodule update --init libs/integer - cp -r $TRAVIS_BUILD_DIR/* libs/utility - ./bootstrap.sh - ./b2 headers diff --git a/appveyor.yml b/appveyor.yml index cb0cf9f..c81a2ac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,6 +37,7 @@ install: - git submodule update --init libs/throw_exception - git submodule update --init libs/type_traits - git submodule update --init libs/container_hash + - git submodule update --init libs/integer - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\utility - cmd /c bootstrap - b2 -d0 headers From 15cfa44937f5243f1b9d97d2ee4ad6979a42c1d3 Mon Sep 17 00:00:00 2001 From: Dimitrij Mijoski Date: Fri, 20 Apr 2018 14:07:33 +0200 Subject: [PATCH 3/4] Boost detail is dependency of boost hash. --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1c6dbdb..1e0f8fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -194,6 +194,7 @@ install: - git submodule update --init libs/type_traits - git submodule update --init libs/container_hash - git submodule update --init libs/integer + - git submodule update --init libs/detail - cp -r $TRAVIS_BUILD_DIR/* libs/utility - ./bootstrap.sh - ./b2 headers diff --git a/appveyor.yml b/appveyor.yml index c81a2ac..b63ff9f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,6 +38,7 @@ install: - git submodule update --init libs/type_traits - git submodule update --init libs/container_hash - git submodule update --init libs/integer + - git submodule update --init libs/detail - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\utility - cmd /c bootstrap - b2 -d0 headers From e2d115db9772ee294d94d8970bea0189de70a81f Mon Sep 17 00:00:00 2001 From: Dimitrij Mijoski Date: Fri, 20 Apr 2018 23:18:31 +0200 Subject: [PATCH 4/4] Use hash_fwd.hpp in string_view for more lightweight dependencies. --- include/boost/utility/string_view.hpp | 2 +- test/string_view_test1.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 0faa8f0..11aa801 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/string_view_test1.cpp b/test/string_view_test1.cpp index 90aec4e..c35bbfa 100644 --- a/test/string_view_test1.cpp +++ b/test/string_view_test1.cpp @@ -12,6 +12,7 @@ #include #include +#include #include