range_overload_test_driver.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright Neil Groves 2013. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. // Acknowledgments:
  10. // Implemented by Andy in response to Ticket 6888 - unique fix
  11. //
  12. #ifndef BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED
  13. #define BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED
  14. #include "range_return_test_driver.hpp"
  15. #include <boost/assert.hpp>
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/test/unit_test.hpp>
  18. namespace boost
  19. {
  20. namespace range_test
  21. {
  22. // A test driver to exercise a test through range_return_test_driver
  23. // plus the overload that determines the return_type by overload
  24. //
  25. // The test driver also contains the code required to check the
  26. // return value correctness.
  27. //
  28. // The TestPolicy needs to implement all those required by
  29. // range_return_test_driver, and additionally
  30. //
  31. // - perform the boost range version of the algorithm that determines
  32. // the return_type by overload
  33. class range_overload_test_driver : range_return_test_driver
  34. {
  35. public:
  36. template< class Container,
  37. class TestPolicy >
  38. void operator()(Container& cont, TestPolicy policy)
  39. {
  40. range_return_test_driver::operator()(cont, policy);
  41. test_range_overload<Container, TestPolicy>()(cont, policy);
  42. }
  43. private:
  44. template< class Container, class TestPolicy >
  45. struct test_range_overload
  46. {
  47. void operator()(Container& cont, TestPolicy policy)
  48. {
  49. typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
  50. typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range_overload<Container> test_range_overload_t;
  51. const range_return_value result_type = test_range_overload_t::result_type;
  52. typedef BOOST_DEDUCED_TYPENAME range_return<Container, result_type>::type range_return_t;
  53. Container reference(cont);
  54. Container test_cont(cont);
  55. test_range_overload_t test_range_overload_fn;
  56. range_return_t range_result = test_range_overload_fn(policy, test_cont);
  57. iterator_t reference_it = policy.reference(reference);
  58. check_results<result_type>::test(test_cont, reference,
  59. range_result, reference_it);
  60. }
  61. };
  62. };
  63. }
  64. }
  65. #endif // include guard