From 28cc18a4bc0222cc192236d559bda5a3d0d30e24 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 Mar 2024 17:44:03 +0200 Subject: [PATCH] Add test with types that return void* from begin/end. Refs #36. --- test/Jamfile.v2 | 3 +++ test/hash_container_test2.cpp | 39 +++++++++++++++++++++++++++++++++++ test/is_range_test4.cpp | 28 +++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test/hash_container_test2.cpp create mode 100644 test/is_range_test4.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 63d9ed3..e431f86 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -125,3 +125,6 @@ run is_tuple_like_test.cpp ; run hash_tuple_like_test.cpp ; run hash_tuple_like_test2.cpp : : : extra ; + +run is_range_test4.cpp ; +run hash_container_test2.cpp ; diff --git a/test/hash_container_test2.cpp b/test/hash_container_test2.cpp new file mode 100644 index 0000000..5c7afea --- /dev/null +++ b/test/hash_container_test2.cpp @@ -0,0 +1,39 @@ +// Copyright 2024 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +struct X1 +{ + void* begin() const { return nullptr; } + void* end() const { return nullptr; } +}; + +std::size_t hash_value( X1 const& ) +{ + return 1; +} + +struct X2 +{ + void const* begin() const { return nullptr; } + void const* end() const { return nullptr; } +}; + +std::size_t hash_value( X2 const& ) +{ + return 2; +} + +int main() +{ + X1 x1; + BOOST_TEST_EQ( boost::hash()( x1 ), 1 ); + + X2 x2; + BOOST_TEST_EQ( boost::hash()( x2 ), 2 ); + + return boost::report_errors(); +} diff --git a/test/is_range_test4.cpp b/test/is_range_test4.cpp new file mode 100644 index 0000000..3de2c81 --- /dev/null +++ b/test/is_range_test4.cpp @@ -0,0 +1,28 @@ +// Copyright 2024 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +struct X1 +{ + void* begin() const; + void* end() const; +}; + +struct X2 +{ + void const* begin() const; + void const* end() const; +}; + +int main() +{ + using boost::container_hash::is_range; + + BOOST_TEST_TRAIT_FALSE((is_range)); + BOOST_TEST_TRAIT_FALSE((is_range)); + + return boost::report_errors(); +}