helpers.hpp 1.4 KB

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