// Copyright 2017 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // // Endian-dependent test // lib1.hpp #include // forward declaration of boost::hash2::hash_append namespace boost { namespace hash2 { template void hash_append( H & h, T const & v ); } // namespace hash2 } // namespace boost // lib1::X namespace lib1 { class X { private: std::string s1_; std::string s2_; template friend void do_hash_append( H& h, X const& x ) { using boost::hash2::hash_append; hash_append( h, x.s1_ ); hash_append( h, x.s2_ ); } public: X(): s1_( "s1" ), s2_( "s2" ) { } }; } // namespace lib1 // lib2.hpp #include #include // boost::uint32_t #include namespace lib2 { class fnv1a { private: boost::uint32_t st_; public: typedef boost::uint32_t result_type; typedef boost::uint32_t size_type; fnv1a(): st_( 0x811C9DC5ul ) { } void update( boost::hash2::byte_type const * p, std::ptrdiff_t n ) { boost::uint32_t h = st_; for( std::ptrdiff_t i = 0; i < n; ++i ) { h ^= static_cast( p[i] ); h *= 0x01000193ul; } st_ = h; } boost::uint32_t result() { boost::uint32_t r = st_; st_ = ( st_ ^ 0xFF ) * 0x01000193ul; return r; } }; } // namespace lib2 // test #include #include #include #include #include template void test( R r ) { { H h; using boost::hash2::hash_append; hash_append( h, std::vector( 3 ) ); BOOST_TEST_EQ( h.result(), r ); } { H h; using boost::hash2::hash_append; hash_append( h, std::list( 3 ) ); BOOST_TEST_EQ( h.result(), r ); } } int main() { test( 2425039999ul ); test( 2425039999ul ); return boost::report_errors(); }