forked from boostorg/utility
Implement boost hash for string_view
This commit is contained in:
@@ -192,6 +192,7 @@ install:
|
|||||||
- git submodule update --init libs/static_assert
|
- git submodule update --init libs/static_assert
|
||||||
- git submodule update --init libs/throw_exception
|
- git submodule update --init libs/throw_exception
|
||||||
- git submodule update --init libs/type_traits
|
- git submodule update --init libs/type_traits
|
||||||
|
- git submodule update --init libs/container_hash
|
||||||
- cp -r $TRAVIS_BUILD_DIR/* libs/utility
|
- cp -r $TRAVIS_BUILD_DIR/* libs/utility
|
||||||
- ./bootstrap.sh
|
- ./bootstrap.sh
|
||||||
- ./b2 headers
|
- ./b2 headers
|
||||||
|
@@ -36,6 +36,7 @@ install:
|
|||||||
- git submodule update --init libs/static_assert
|
- git submodule update --init libs/static_assert
|
||||||
- git submodule update --init libs/throw_exception
|
- git submodule update --init libs/throw_exception
|
||||||
- git submodule update --init libs/type_traits
|
- git submodule update --init libs/type_traits
|
||||||
|
- git submodule update --init libs/container_hash
|
||||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\utility
|
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\utility
|
||||||
- cmd /c bootstrap
|
- cmd /c bootstrap
|
||||||
- b2 -d0 headers
|
- b2 -d0 headers
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
#include <boost/utility/string_view_fwd.hpp>
|
#include <boost/utility/string_view_fwd.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
|
#include <boost/container_hash/hash.hpp>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -690,6 +691,10 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <class charT, class traits>
|
||||||
|
std::size_t hash_value(basic_string_view<charT, traits> s) {
|
||||||
|
return boost::hash_range(s.begin(), s.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@@ -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<std::string> hstr;
|
||||||
|
boost::hash<string_view> hsv;
|
||||||
|
BOOST_TEST(hsv(ref) == hstr(str));
|
||||||
|
}
|
||||||
|
|
||||||
const char *test_strings [] = {
|
const char *test_strings [] = {
|
||||||
"",
|
"",
|
||||||
"1",
|
"1",
|
||||||
@@ -102,6 +110,7 @@ int main()
|
|||||||
test_substr ( *p );
|
test_substr ( *p );
|
||||||
test_remove ( *p );
|
test_remove ( *p );
|
||||||
null_tests ( *p );
|
null_tests ( *p );
|
||||||
|
test_hash( *p );
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user