diff --git a/headers/flat_hpp/flat_map.hpp b/headers/flat_hpp/flat_map.hpp index e972657..6bf2379 100644 --- a/headers/flat_hpp/flat_map.hpp +++ b/headers/flat_hpp/flat_map.hpp @@ -319,7 +319,10 @@ namespace flat_hpp : 0; } - void swap(flat_map& other) { + void swap(flat_map& other) + noexcept(std::is_nothrow_swappable_v + && std::is_nothrow_swappable_v) + { using std::swap; swap( static_cast(*this), @@ -397,6 +400,7 @@ namespace flat_hpp void swap( flat_map& l, flat_map& r) + noexcept(noexcept(l.swap(r))) { l.swap(r); } diff --git a/headers/flat_hpp/flat_multimap.hpp b/headers/flat_hpp/flat_multimap.hpp index adbf5ed..b5131d3 100644 --- a/headers/flat_hpp/flat_multimap.hpp +++ b/headers/flat_hpp/flat_multimap.hpp @@ -315,7 +315,10 @@ namespace flat_hpp return r; } - void swap(flat_multimap& other) { + void swap(flat_multimap& other) + noexcept(std::is_nothrow_swappable_v + && std::is_nothrow_swappable_v) + { using std::swap; swap( static_cast(*this), @@ -393,6 +396,7 @@ namespace flat_hpp void swap( flat_multimap& l, flat_multimap& r) + noexcept(noexcept(l.swap(r))) { l.swap(r); } diff --git a/headers/flat_hpp/flat_multiset.hpp b/headers/flat_hpp/flat_multiset.hpp index f944c05..128906f 100644 --- a/headers/flat_hpp/flat_multiset.hpp +++ b/headers/flat_hpp/flat_multiset.hpp @@ -230,7 +230,10 @@ namespace flat_hpp return r; } - void swap(flat_multiset& other) { + void swap(flat_multiset& other) + noexcept(std::is_nothrow_swappable_v + && std::is_nothrow_swappable_v) + { using std::swap; swap( static_cast(*this), @@ -301,6 +304,7 @@ namespace flat_hpp void swap( flat_multiset& l, flat_multiset& r) + noexcept(noexcept(l.swap(r))) { l.swap(r); } diff --git a/headers/flat_hpp/flat_set.hpp b/headers/flat_hpp/flat_set.hpp index 77f3999..366e810 100644 --- a/headers/flat_hpp/flat_set.hpp +++ b/headers/flat_hpp/flat_set.hpp @@ -234,7 +234,10 @@ namespace flat_hpp : 0; } - void swap(flat_set& other) { + void swap(flat_set& other) + noexcept(std::is_nothrow_swappable_v + && std::is_nothrow_swappable_v) + { using std::swap; swap( static_cast(*this), @@ -305,6 +308,7 @@ namespace flat_hpp void swap( flat_set& l, flat_set& r) + noexcept(noexcept(l.swap(r))) { l.swap(r); } diff --git a/untests/flat_map_tests.cpp b/untests/flat_map_tests.cpp index ccad8af..6d7a79e 100644 --- a/untests/flat_map_tests.cpp +++ b/untests/flat_map_tests.cpp @@ -38,6 +38,15 @@ namespace void swap(dummy_less2&, dummy_less2&) noexcept { } + template < typename T > + class dummy_less3 { + dummy_less3() = default; + dummy_less3(dummy_less3&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -57,50 +66,30 @@ TEST_CASE("flat_map") { using alloc_t = std::allocator>; using map_t = flat_map, std::vector, alloc_t>>; using map2_t = flat_map>; + using map3_t = flat_map>; - static_assert( - std::is_nothrow_default_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_assignable_v, - "unit test static error"); + STATIC_REQUIRE(std::is_nothrow_default_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_assignable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(!std::is_nothrow_swappable_v); } SECTION("types") { using map_t = flat_map; - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v>); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v&>, - "unit test static error"); - static_assert( - std::is_same_v&>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v&>); + STATIC_REQUIRE(std::is_same_v&>); - static_assert( - std::is_same_v*>, - "unit test static error"); - static_assert( - std::is_same_v*>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v*>); + STATIC_REQUIRE(std::is_same_v*>); } SECTION("ctors") { using alloc_t = std::allocator< diff --git a/untests/flat_multimap_tests.cpp b/untests/flat_multimap_tests.cpp index 590c59d..bc550f1 100644 --- a/untests/flat_multimap_tests.cpp +++ b/untests/flat_multimap_tests.cpp @@ -38,6 +38,15 @@ namespace void swap(dummy_less2&, dummy_less2&) noexcept { } + template < typename T > + class dummy_less3 { + dummy_less3() = default; + dummy_less3(dummy_less3&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -57,50 +66,30 @@ TEST_CASE("flat_multimap") { using alloc_t = std::allocator>; using map_t = flat_multimap, std::vector, alloc_t>>; using map2_t = flat_multimap>; + using map3_t = flat_multimap>; - static_assert( - std::is_nothrow_default_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_assignable_v, - "unit test static error"); + STATIC_REQUIRE(std::is_nothrow_default_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_assignable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(!std::is_nothrow_swappable_v); } SECTION("types") { using map_t = flat_multimap; - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v>); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v&>, - "unit test static error"); - static_assert( - std::is_same_v&>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v&>); + STATIC_REQUIRE(std::is_same_v&>); - static_assert( - std::is_same_v*>, - "unit test static error"); - static_assert( - std::is_same_v*>, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v*>); + STATIC_REQUIRE(std::is_same_v*>); } SECTION("ctors") { using alloc_t = std::allocator< diff --git a/untests/flat_multiset_tests.cpp b/untests/flat_multiset_tests.cpp index 4d9fa0b..014cb1a 100644 --- a/untests/flat_multiset_tests.cpp +++ b/untests/flat_multiset_tests.cpp @@ -38,6 +38,15 @@ namespace void swap(dummy_less2&, dummy_less2&) noexcept { } + template < typename T > + class dummy_less3 { + dummy_less3() = default; + dummy_less3(dummy_less3&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -57,47 +66,29 @@ TEST_CASE("flat_multiset") { using alloc_t = std::allocator; using set_t = flat_multiset, std::vector>; using set2_t = flat_multiset>; + using set3_t = flat_multiset>; - static_assert( - std::is_nothrow_default_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_assignable_v, - "unit test static error"); + STATIC_REQUIRE(std::is_nothrow_default_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_assignable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(!std::is_nothrow_swappable_v); } SECTION("types") { using set_t = flat_multiset; - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); } SECTION("ctors") { using alloc_t = std::allocator; diff --git a/untests/flat_set_tests.cpp b/untests/flat_set_tests.cpp index 5419ef1..40a04c4 100644 --- a/untests/flat_set_tests.cpp +++ b/untests/flat_set_tests.cpp @@ -38,6 +38,15 @@ namespace void swap(dummy_less2&, dummy_less2&) noexcept { } + template < typename T > + class dummy_less3 { + dummy_less3() = default; + dummy_less3(dummy_less3&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -57,47 +66,29 @@ TEST_CASE("flat_set") { using alloc_t = std::allocator; using set_t = flat_set, std::vector>; using set2_t = flat_set>; + using set3_t = flat_set>; - static_assert( - std::is_nothrow_default_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_constructible_v, - "unit test static error"); - static_assert( - std::is_nothrow_move_assignable_v, - "unit test static error"); + STATIC_REQUIRE(std::is_nothrow_default_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_constructible_v); + STATIC_REQUIRE(std::is_nothrow_move_assignable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(std::is_nothrow_swappable_v); + STATIC_REQUIRE(!std::is_nothrow_swappable_v); } SECTION("types") { using set_t = flat_set; - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); - static_assert( - std::is_same_v, - "unit test static error"); - static_assert( - std::is_same_v, - "unit test static error"); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); } SECTION("ctors") { using alloc_t = std::allocator;