diff options
Diffstat (limited to 'libs/functional/hash')
17 files changed, 449 insertions, 55 deletions
diff --git a/libs/functional/hash/doc/changes.qbk b/libs/functional/hash/doc/changes.qbk index eb6572f9f6..3aa3dee414 100644 --- a/libs/functional/hash/doc/changes.qbk +++ b/libs/functional/hash/doc/changes.qbk @@ -123,4 +123,13 @@ * Avoid warning due with gcc's `-Wconversion` flag. +[h2 Boost 1.50.0] + +* [@http://svn.boost.org/trac/boost/ticket/6771 Ticket 6771]: + Avoid gcc's `-Wfloat-equal` warning. +* [@http://svn.boost.org/trac/boost/ticket/6806 Ticket 6806]: + Support `std::array` and `std::tuple` when available. +* Add deprecation warning to the long deprecated + `boost/functional/detail/container_fwd.hpp`. + [endsect] diff --git a/libs/functional/hash/doc/ref.xml b/libs/functional/hash/doc/ref.xml index 318bf85398..d7c427c508 100644 --- a/libs/functional/hash/doc/ref.xml +++ b/libs/functional/hash/doc/ref.xml @@ -55,6 +55,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) is defined. The specializations are still defined, so only the specializations required by TR1 are defined. </para> + <para> + Forward declared in + <code><boost/functional/hash_fwd.hpp></code> + </para> </notes> <throws><para> Only throws if @@ -451,6 +455,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) <para><functionname>hash_value</functionname> is called without qualification, so that overloads can be found via ADL.</para> <para>This is an extension to TR1</para> + <para> + Forward declared in + <code><boost/functional/hash_fwd.hpp></code> + </para> </notes> <throws> Only throws if <functionname>hash_value</functionname>(T) throws. @@ -499,15 +507,14 @@ for(; first != last; ++first) return seed; </programlisting> - </para>For the three arguments overload: + </para> + <para>For the three arguments overload:</para> <programlisting> for(; first != last; ++first) { <functionname>hash_combine</functionname>(seed, *first); } </programlisting> - <para> - </para> </effects> <notes> <para> @@ -516,6 +523,10 @@ for(; first != last; ++first) container. </para> <para>This is an extension to TR1</para> + <para> + Forward declared in + <code><boost/functional/hash_fwd.hpp></code> + </para> </notes> <throws><para> Only throws if <code><functionname>hash_value</functionname>(std::iterator_traits<It>::value_type)</code> @@ -744,6 +755,25 @@ for(; first != last; ++first) <parameter name="val"><paramtype>std::type_index</paramtype></parameter> </signature> + <signature> + <template> + <template-type-parameter name="T"/> + <template-nontype-parameter name="N"> + <type>std::size_t</type> + </template-nontype-parameter> + </template> + <type>std::size_t</type> + <parameter name="val"><paramtype>std::array<T, N> const&</paramtype></parameter> + </signature> + + <signature> + <template> + <template-type-parameter name="T" pack="1"/> + </template> + <type>std::size_t</type> + <parameter name="val"><paramtype>std::tuple<T...></paramtype></parameter> + </signature> + <description><para> Generally shouldn't be called directly by users, instead they should use <classname>boost::hash</classname>, <functionname>boost::hash_range</functionname> @@ -809,7 +839,8 @@ for(; first != last; ++first) <code>std::set<K, C, A></code>, <code>std::multiset<K, C, A></code>, <code>std::map<K, T, C, A></code>, - <code>std::multimap<K, T, C, A></code> + <code>std::multimap<K, T, C, A></code>, + <code>std::array<T, N></code> </entry> <entry><code>hash_range(val.begin(), val.end())</code></entry> </row> @@ -821,6 +852,14 @@ for(; first != last; ++first) return seed;</programlisting></entry> </row> <row> + <entry><code>std::tuple<T...></code></entry> + <entry><programlisting>size_t seed = 0; +<functionname>hash_combine</functionname>(seed, get<0>(val)); +<functionname>hash_combine</functionname>(seed, get<1>(val)); +// .... +return seed;</programlisting></entry> + </row> + <row> <entry> <code>std::complex<T></code> </entry> diff --git a/libs/functional/hash/doc/tutorial.qbk b/libs/functional/hash/doc/tutorial.qbk index 81c1b15fc3..59067a7734 100644 --- a/libs/functional/hash/doc/tutorial.qbk +++ b/libs/functional/hash/doc/tutorial.qbk @@ -198,5 +198,15 @@ To calculate the hash of an iterator range you can use [funcref boost::hash_rang std::vector<std::string> some_strings; std::size_t hash = ``[funcref boost::hash_range]``(some_strings.begin(), some_strings.end()); -[endsect] +Note that when writing template classes, you might not want to include the main +hash header as it's quite an expensive include that brings in a lot of other +headers, so instead you can include the `<boost/functional/hash_fwd.hpp>` +header which forward declares [classref boost::hash], +[funcref boost::hash_range] and [funcref boost::hash_combine]. You'll need to +include the main header before instantiating [classref boost::hash]. When using +a container that uses [classref boost::hash] it should do that for you, so your +type will work fine with the boost hash containers. There's an example of this +in [@boost:/libs/functional/hash/examples/template.hpp template.hpp] and +[@boost:/libs/functional/hash/examples/template.cpp template.cpp]. +[endsect] diff --git a/libs/functional/hash/examples/Jamfile.v2 b/libs/functional/hash/examples/Jamfile.v2 index dc5bdce3f1..62916211e9 100644 --- a/libs/functional/hash/examples/Jamfile.v2 +++ b/libs/functional/hash/examples/Jamfile.v2 @@ -6,3 +6,4 @@ run books.cpp ; run point.cpp ; run portable.cpp ; +run template.cpp ; diff --git a/libs/functional/hash/examples/template.cpp b/libs/functional/hash/examples/template.cpp new file mode 100644 index 0000000000..d74f0a9ca1 --- /dev/null +++ b/libs/functional/hash/examples/template.cpp @@ -0,0 +1,18 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "template.hpp" +#include <cassert> +#include <boost/unordered_set.hpp> + +int main() +{ + typedef my_pair<int, float> pair; + boost::unordered_set<pair> pair_set; + pair_set.emplace(10, 0.5f); + + assert(pair_set.find(pair(10, 0.5f)) != pair_set.end()); + assert(pair_set.find(pair(10, 0.6f)) == pair_set.end()); +} diff --git a/libs/functional/hash/examples/template.hpp b/libs/functional/hash/examples/template.hpp new file mode 100644 index 0000000000..b630704800 --- /dev/null +++ b/libs/functional/hash/examples/template.hpp @@ -0,0 +1,36 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// This is an example of how to write a hash function for a template +// class. + +#include <boost/functional/hash_fwd.hpp> + +template <typename A, typename B> +class my_pair +{ + A value1; + B value2; +public: + my_pair(A const& v1, B const& v2) + : value1(v1), value2(v2) + {} + + bool operator==(my_pair const& other) const + { + return value1 == other.value1 && + value2 == other.value2; + } + + friend std::size_t hash_value(my_pair const& p) + { + std::size_t seed = 0; + boost::hash_combine(seed, p.value1); + boost::hash_combine(seed, p.value2); + + return seed; + } +}; + diff --git a/libs/functional/hash/test/Jamfile.v2 b/libs/functional/hash/test/Jamfile.v2 index 7b3ccd9cf2..fc731d26f6 100644 --- a/libs/functional/hash/test/Jamfile.v2 +++ b/libs/functional/hash/test/Jamfile.v2 @@ -10,8 +10,8 @@ project hash-tests <warnings>all <toolset>intel:<warnings>on <toolset>intel:<cxxflags>-strict-ansi - <toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" - <toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + <toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" + <toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" <toolset>msvc:<warnings-as-errors>on #<toolset>gcc:<warnings-as-errors>on #<toolset>darwin:<warnings-as-errors>on @@ -19,49 +19,39 @@ project hash-tests test-suite functional/hash : - [ run hash_fwd_test_1.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_fwd_test_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_number_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_pointer_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_function_pointer_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_float_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_long_double_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_string_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_range_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_custom_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_global_namespace_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_friend_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_built_in_array_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_value_array_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_vector_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_list_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_deque_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_set_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_map_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_complex_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_type_index_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_test.cpp link_test_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_ext_test.cpp link_no_ext_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run extensions_hpp_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail hash_no_ext_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail namespace_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail implicit_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_1.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - ; - -test-suite functional/hash_implicit_casts - : - [ run hash_number_test.cpp : : : : implicit_number ] - [ run hash_pointer_test.cpp : : : : implicit_pointer ] - [ run hash_function_pointer_test.cpp : : : : implicit_function_pointer ] - [ run hash_float_test.cpp : : : : implicit_float ] - [ run hash_string_test.cpp : : : : implicit_string ] - [ run hash_range_test.cpp : : : : implicit_range ] - [ run hash_custom_test.cpp : : : : implicit_custom ] - [ run hash_built_in_array_test.cpp : : : : implicit_built_in_array ] - [ run link_test.cpp link_test_2.cpp : : : : implicit_link ] - [ run implicit_fail_test.cpp : : : : implicit_test ] + [ run hash_fwd_test_1.cpp ] + [ run hash_fwd_test_2.cpp ] + [ run hash_number_test.cpp ] + [ run hash_pointer_test.cpp ] + [ run hash_function_pointer_test.cpp ] + [ run hash_float_test.cpp ] + [ run hash_long_double_test.cpp ] + [ run hash_string_test.cpp ] + [ run hash_range_test.cpp ] + [ run hash_custom_test.cpp ] + [ run hash_global_namespace_test.cpp ] + [ run hash_friend_test.cpp ] + [ run hash_built_in_array_test.cpp ] + [ run hash_value_array_test.cpp ] + [ run hash_vector_test.cpp ] + [ run hash_list_test.cpp ] + [ run hash_deque_test.cpp ] + [ run hash_set_test.cpp ] + [ run hash_map_test.cpp ] + [ run hash_complex_test.cpp ] + [ run hash_type_index_test.cpp ] + [ run hash_std_array_test.cpp ] + [ run hash_std_tuple_test.cpp ] + [ run hash_std_smart_ptr_test.cpp ] + [ run link_test.cpp link_test_2.cpp ] + [ run link_ext_test.cpp link_no_ext_test.cpp ] + [ run extensions_hpp_test.cpp ] + [ compile-fail hash_no_ext_fail_test.cpp ] + [ compile-fail namespace_fail_test.cpp ] + [ run implicit_test.cpp ] + [ run hash_no_ext_macro_1.cpp ] + [ run hash_no_ext_macro_2.cpp ] + [ compile deprecated_container_fwd.cpp ] ; test-suite functional/hash_no_ext diff --git a/libs/functional/hash/test/deprecated_container_fwd.cpp b/libs/functional/hash/test/deprecated_container_fwd.cpp new file mode 100644 index 0000000000..1c6e12b7da --- /dev/null +++ b/libs/functional/hash/test/deprecated_container_fwd.cpp @@ -0,0 +1,14 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/functional/detail/container_fwd.hpp> + +typedef std::vector<int, std::allocator<int> > int_vector; + +#include <vector> + +int main() { + int_vector x; +} diff --git a/libs/functional/hash/test/hash_complex_test.cpp b/libs/functional/hash/test/hash_complex_test.cpp index 67e2aff0b0..bb1592cffc 100644 --- a/libs/functional/hash/test/hash_complex_test.cpp +++ b/libs/functional/hash/test/hash_complex_test.cpp @@ -35,6 +35,10 @@ int main() {} #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + #include <complex> #include <sstream> #include <boost/limits.hpp> diff --git a/libs/functional/hash/test/hash_float_test.hpp b/libs/functional/hash/test/hash_float_test.hpp index dd1358e108..c608915103 100644 --- a/libs/functional/hash/test/hash_float_test.hpp +++ b/libs/functional/hash/test/hash_float_test.hpp @@ -30,6 +30,10 @@ #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + char const* float_type(float*) { return "float"; } char const* float_type(double*) { return "double"; } char const* float_type(long double*) { return "long double"; } diff --git a/libs/functional/hash/test/hash_map_test.cpp b/libs/functional/hash/test/hash_map_test.cpp index 2f813c3af0..7e117c72a6 100644 --- a/libs/functional/hash/test/hash_map_test.cpp +++ b/libs/functional/hash/test/hash_map_test.cpp @@ -27,7 +27,7 @@ using std::multimap; #define CONTAINER_TYPE multimap #include "./hash_map_test.hpp" -#endif // TEST_EXTENSTIONS +#endif // TEST_EXTENSIONS int main() { diff --git a/libs/functional/hash/test/hash_number_test.cpp b/libs/functional/hash/test/hash_number_test.cpp index b989d22c30..b233c71b4d 100644 --- a/libs/functional/hash/test/hash_number_test.cpp +++ b/libs/functional/hash/test/hash_number_test.cpp @@ -28,6 +28,10 @@ #pragma warning(disable:4310) // cast truncates constant value #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + template <class T> void numeric_test(T*) { diff --git a/libs/functional/hash/test/hash_std_array_test.cpp b/libs/functional/hash/test/hash_std_array_test.cpp new file mode 100644 index 0000000000..6f67a67e37 --- /dev/null +++ b/libs/functional/hash/test/hash_std_array_test.cpp @@ -0,0 +1,103 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include <functional> +# else +# include <boost/functional/hash.hpp> +# endif +#endif + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_ARRAY) +#define TEST_ARRAY +#include <array> +#include <vector> +#endif + +#ifdef TEST_ARRAY + +template <typename T> +void array_tests(T const& v) { + boost::hash<typename T::value_type> hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_array_test() { +/* + boost::hash<std::array<int, 0> > empty_array_hash; + std::array<int, 0> empty_array; + BOOST_TEST(empty_array_hash(empty_array) == boost::hash_value(empty_array)); +*/ +} + +void int_1_array_test() +{ + std::vector<std::array<int, 1> > arrays; + std::array<int, 1> val; + val[0] = 0; + arrays.push_back(val); + val[0] = 1; + arrays.push_back(val); + val[0] = 2; + arrays.push_back(val); + array_tests(arrays); +} + +void string_1_array_test() +{ + std::vector<std::array<std::string, 1> > arrays; + std::array<std::string, 1> val; + arrays.push_back(val); + val[0] = "one"; + arrays.push_back(val); + val[0] = "two"; + arrays.push_back(val); + array_tests(arrays); +} + +void string_3_array_test() +{ + std::vector<std::array<std::string,3 > > arrays; + std::array<std::string, 3> val; + arrays.push_back(val); + val[0] = "one"; + arrays.push_back(val); + val[0] = ""; val[1] = "one"; val[2] = ""; + arrays.push_back(val); + val[0] = ""; val[1] = ""; val[2] = "one"; + arrays.push_back(val); + val[0] = "one"; val[1] = "one"; val[2] = "one"; + arrays.push_back(val); + val[0] = "one"; val[1] = "two"; val[2] = "three"; + arrays.push_back(val); + array_tests(arrays); +} + +#endif // TEST_ARRAY + +int main() +{ +#ifdef TEST_ARRAY + empty_array_test(); + int_1_array_test(); + string_1_array_test(); + string_3_array_test(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_std_smart_ptr_test.cpp b/libs/functional/hash/test/hash_std_smart_ptr_test.cpp new file mode 100644 index 0000000000..74525854f8 --- /dev/null +++ b/libs/functional/hash/test/hash_std_smart_ptr_test.cpp @@ -0,0 +1,80 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include <functional> +#else +# include <boost/functional/hash.hpp> +#endif + +#include <boost/detail/lightweight_test.hpp> +#include "./compile_time.hpp" + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_SMART_PTR) +#define TEST_SMART_PTRS +#include <memory> +#endif + +#ifdef TEST_SMART_PTRS + +void shared_ptr_tests() +{ + std::shared_ptr<int> x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash<std::shared_ptr<int> > x1; + HASH_NAMESPACE::hash<std::shared_ptr<int> > x2; + + std::shared_ptr<int> ptr1(new int(10)); + std::shared_ptr<int> ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + ptr2 = ptr1; + BOOST_TEST(x1(ptr1) == x2(ptr2)); +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); + BOOST_TEST(x1(ptr1) == HASH_NAMESPACE::hash_value(ptr2)); +#endif +} + +void unique_ptr_tests() +{ + std::unique_ptr<int> x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash<std::unique_ptr<int> > x1; + HASH_NAMESPACE::hash<std::unique_ptr<int> > x2; + + std::unique_ptr<int> ptr1(new int(10)); + std::unique_ptr<int> ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); +#endif +} + +#endif + +int main() +{ +#ifdef TEST_SMART_PTRS + shared_ptr_tests(); + unique_ptr_tests(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_std_tuple_test.cpp b/libs/functional/hash/test/hash_std_tuple_test.cpp new file mode 100644 index 0000000000..9314336af5 --- /dev/null +++ b/libs/functional/hash/test/hash_std_tuple_test.cpp @@ -0,0 +1,77 @@ + +// Copyright 2012 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include <functional> +# else +# include <boost/functional/hash.hpp> +# endif +#endif + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) +#define TEST_TUPLE +#include <tuple> +#include <vector> +#endif + +#ifdef TEST_TUPLE + +template <typename T> +void tuple_tests(T const& v) { + boost::hash<typename T::value_type> hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_tuple_test() { + boost::hash<std::tuple<> > empty_tuple_hash; + std::tuple<> empty_tuple; + BOOST_TEST(empty_tuple_hash(empty_tuple) == boost::hash_value(empty_tuple)); +} + +void int_tuple_test() { + std::vector<std::tuple<int> > int_tuples; + int_tuples.push_back(std::make_tuple(0)); + int_tuples.push_back(std::make_tuple(1)); + int_tuples.push_back(std::make_tuple(2)); + tuple_tests(int_tuples); +} + +void int_string_tuple_test() { + std::vector<std::tuple<int, std::string> > int_string_tuples; + int_string_tuples.push_back(std::make_tuple(0, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(2, std::string("two"))); + int_string_tuples.push_back(std::make_tuple(0, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(0, std::string(""))); + int_string_tuples.push_back(std::make_tuple(1, std::string(""))); + tuple_tests(int_string_tuples); +} + +#endif // TEST_TUPLE + +int main() +{ +#ifdef TEST_TUPLE + empty_tuple_test(); + int_tuple_test(); + int_string_tuple_test(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_type_index_test.cpp b/libs/functional/hash/test/hash_type_index_test.cpp index 7892918c42..27fcfff18f 100644 --- a/libs/functional/hash/test/hash_type_index_test.cpp +++ b/libs/functional/hash/test/hash_type_index_test.cpp @@ -13,17 +13,21 @@ #include <boost/config.hpp> #include <boost/detail/lightweight_test.hpp> -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) #include <typeindex> void test_type_index() { + HASH_NAMESPACE::hash<std::type_index> hasher; + +#if defined(BOOST_NO_TYPEID) + std::cout<<"Unable to test std::type_index, as typeid isn't available" + <<std::endl; +#else std::type_index int_index = typeid(int); std::type_index int2_index = typeid(int); std::type_index char_index = typeid(char); - HASH_NAMESPACE::hash<std::type_index> hasher; - BOOST_TEST(hasher(int_index) == int_index.hash_code()); BOOST_TEST(hasher(int_index) == int2_index.hash_code()); BOOST_TEST(hasher(char_index) == char_index.hash_code()); @@ -33,12 +37,13 @@ void test_type_index() { BOOST_TEST(hasher(int_index) == hasher(int2_index)); BOOST_TEST(hasher(int_index) != hasher(char_index)); +#endif } #endif int main() { -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) test_type_index(); #else std::cout<<"<type_index> not available."<<std::endl; diff --git a/libs/functional/hash/test/implicit_fail_test.cpp b/libs/functional/hash/test/implicit_test.cpp index e48bbcdd18..e48bbcdd18 100644 --- a/libs/functional/hash/test/implicit_fail_test.cpp +++ b/libs/functional/hash/test/implicit_test.cpp |