1 2 // Copyright 2006-2009 Daniel James. 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #if !defined(BOOST_UNORDERED_TEST_HELPERS_HEADER) 7 #define BOOST_UNORDERED_TEST_HELPERS_HEADER 8 9 #include <iterator> 10 11 namespace test { 12 template <class Container> struct get_key_impl 13 { 14 typedef typename Container::key_type key_type; 15 get_keytest::get_key_impl16 static key_type const& get_key(key_type const& x) { return x; } 17 18 template <class T> get_keytest::get_key_impl19 static key_type const& get_key(std::pair<key_type, T> const& x, char = 0) 20 { 21 return x.first; 22 } 23 24 template <class T> get_keytest::get_key_impl25 static key_type const& get_key( 26 std::pair<key_type const, T> const& x, unsigned char = 0) 27 { 28 return x.first; 29 } 30 }; 31 32 template <class Container, class T> get_key(T const & x)33 inline typename Container::key_type const& get_key(T const& x) 34 { 35 return get_key_impl<Container>::get_key(x); 36 } 37 38 // test::next 39 // 40 // Increments an iterator by 1 or a given value. 41 // Like boost::next, but simpler. 42 // Mainly because boost::next uses an MPL file 43 // which causes warnings. 44 next(Iterator it)45 template <typename Iterator> Iterator next(Iterator it) { return ++it; } 46 47 template <typename Iterator, typename IntType> next(Iterator it,IntType x)48 Iterator next(Iterator it, IntType x) 49 { 50 std::advance(it, 51 static_cast<typename std::iterator_traits<Iterator>::difference_type>(x)); 52 return it; 53 } 54 } 55 56 #endif 57