From daeaf5e98b366aeefe6397ce2f6a0d2b07a37a3c Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 5 Jan 2018 17:10:13 +0000 Subject: [PATCH] Flexible exception testing hash/equal_to --- test/unordered/noexcept_tests.cpp | 80 +++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/test/unordered/noexcept_tests.cpp b/test/unordered/noexcept_tests.cpp index 98dfa2b2..29c805a2 100644 --- a/test/unordered/noexcept_tests.cpp +++ b/test/unordered/noexcept_tests.cpp @@ -42,25 +42,36 @@ namespace noexcept_tests { } } - class hash_nothrow_move : boost::hash + template + class hash_nothrow : boost::hash { - BOOST_COPYABLE_AND_MOVABLE(hash_nothrow_move) + BOOST_COPYABLE_AND_MOVABLE(hash_nothrow) typedef boost::hash base; public: - hash_nothrow_move(BOOST_RV_REF(hash_nothrow_move)) BOOST_NOEXCEPT {} + hash_nothrow(BOOST_RV_REF(hash_nothrow)) + BOOST_NOEXCEPT_IF(nothrow_move_construct) + { + if (!nothrow_move_construct) { + test_throw("Move Constructor"); + } + } - hash_nothrow_move() { test_throw("Constructor"); } - hash_nothrow_move(hash_nothrow_move const&) { test_throw("Copy"); } - hash_nothrow_move& operator=(BOOST_COPY_ASSIGN_REF(hash_nothrow_move)) + hash_nothrow() { test_throw("Constructor"); } + hash_nothrow(hash_nothrow const&) { test_throw("Copy"); } + hash_nothrow& operator=(BOOST_COPY_ASSIGN_REF(hash_nothrow)) { test_throw("Assign"); return *this; } - hash_nothrow_move& operator=(BOOST_RV_REF(hash_nothrow_move)) + hash_nothrow& operator=(BOOST_RV_REF(hash_nothrow)) + BOOST_NOEXCEPT_IF(nothrow_move_assign) { - test_throw("Move Assign"); + if (!nothrow_move_assign) { + test_throw("Move Assign"); + } return *this; } std::size_t operator()(int x) const @@ -68,36 +79,65 @@ namespace noexcept_tests { test_throw("Operator"); return static_cast(*this)(x); } + friend void swap(hash_nothrow&, hash_nothrow&) + BOOST_NOEXCEPT_IF(nothrow_swap) + { + if (!nothrow_swap) { + test_throw("Swap"); + } + } }; - class equal_to_nothrow_move : std::equal_to - { - BOOST_COPYABLE_AND_MOVABLE(equal_to_nothrow_move) + typedef hash_nothrow hash_nothrow_move; - typedef std::equal_to base; + template + class equal_to_nothrow + { + BOOST_COPYABLE_AND_MOVABLE(equal_to_nothrow) + + typedef boost::hash base; public: - equal_to_nothrow_move(BOOST_RV_REF(equal_to_nothrow_move)) BOOST_NOEXCEPT {} - equal_to_nothrow_move() { test_throw("Constructor"); } - equal_to_nothrow_move(equal_to_nothrow_move const&) { test_throw("Copy"); } - equal_to_nothrow_move& operator=( - BOOST_COPY_ASSIGN_REF(equal_to_nothrow_move)) + equal_to_nothrow(BOOST_RV_REF(equal_to_nothrow)) + BOOST_NOEXCEPT_IF(nothrow_move_construct) + { + if (!nothrow_move_construct) { + test_throw("Move Constructor"); + } + } + + equal_to_nothrow() { test_throw("Constructor"); } + equal_to_nothrow(equal_to_nothrow const&) { test_throw("Copy"); } + equal_to_nothrow& operator=(BOOST_COPY_ASSIGN_REF(equal_to_nothrow)) { test_throw("Assign"); return *this; } - equal_to_nothrow_move& operator=(BOOST_RV_REF(equal_to_nothrow_move)) + equal_to_nothrow& operator=(BOOST_RV_REF(equal_to_nothrow)) + BOOST_NOEXCEPT_IF(nothrow_move_assign) { - test_throw("Move Assign"); + if (!nothrow_move_assign) { + test_throw("Move Assign"); + } return *this; } std::size_t operator()(int x, int y) const { test_throw("Operator"); - return static_cast(*this)(x, y); + return x == y; + } + friend void swap(equal_to_nothrow&, equal_to_nothrow&) + BOOST_NOEXCEPT_IF(nothrow_swap) + { + if (!nothrow_swap) { + test_throw("Swap"); + } } }; + typedef equal_to_nothrow equal_to_nothrow_move; + bool have_is_nothrow_move = false; UNORDERED_AUTO_TEST (check_is_nothrow_move) {