strong.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2005-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_STRONG_HEADER)
  5. #define BOOST_UNORDERED_TEST_HELPERS_STRONG_HEADER
  6. #include "./equivalent.hpp"
  7. #include "./exception_test.hpp"
  8. #include "./list.hpp"
  9. #include <boost/config.hpp>
  10. #include <iterator>
  11. namespace test {
  12. template <class X> class strong
  13. {
  14. typedef test::list<typename X::value_type> values_type;
  15. values_type values_;
  16. unsigned int allocations_;
  17. public:
  18. void store(X const& x, unsigned int allocations = 0)
  19. {
  20. DISABLE_EXCEPTIONS;
  21. values_.clear();
  22. values_.insert(x.cbegin(), x.cend());
  23. allocations_ = allocations;
  24. }
  25. void test(X const& x, unsigned int allocations = 0) const
  26. {
  27. if (!(x.size() == values_.size() && test::equal(x.cbegin(), x.cend(),
  28. values_.begin(), test::equivalent)))
  29. BOOST_ERROR("Strong exception safety failure.");
  30. if (allocations != allocations_)
  31. BOOST_ERROR("Strong exception failure: extra allocations.");
  32. }
  33. };
  34. }
  35. #endif