diff --git a/headers/flat_hpp/flat_map.hpp b/headers/flat_hpp/flat_map.hpp index 191e310..e972657 100644 --- a/headers/flat_hpp/flat_map.hpp +++ b/headers/flat_hpp/flat_map.hpp @@ -99,8 +99,8 @@ namespace flat_hpp }; public: flat_map() - noexcept(std::is_nothrow_default_constructible::value - && std::is_nothrow_default_constructible::value) {} + noexcept(std::is_nothrow_default_constructible_v + && std::is_nothrow_default_constructible_v) {} explicit flat_map(const Compare& c) : base_type(c) {} diff --git a/headers/flat_hpp/flat_multimap.hpp b/headers/flat_hpp/flat_multimap.hpp index f6b5b7b..adbf5ed 100644 --- a/headers/flat_hpp/flat_multimap.hpp +++ b/headers/flat_hpp/flat_multimap.hpp @@ -99,8 +99,8 @@ namespace flat_hpp }; public: flat_multimap() - noexcept(std::is_nothrow_default_constructible::value - && std::is_nothrow_default_constructible::value) {} + noexcept(std::is_nothrow_default_constructible_v + && std::is_nothrow_default_constructible_v) {} explicit flat_multimap(const Compare& c) : base_type(c) {} diff --git a/headers/flat_hpp/flat_multiset.hpp b/headers/flat_hpp/flat_multiset.hpp index a3b9c17..f944c05 100644 --- a/headers/flat_hpp/flat_multiset.hpp +++ b/headers/flat_hpp/flat_multiset.hpp @@ -44,8 +44,8 @@ namespace flat_hpp using const_reverse_iterator = typename Container::const_reverse_iterator; public: flat_multiset() - noexcept(std::is_nothrow_default_constructible::value - && std::is_nothrow_default_constructible::value) {} + noexcept(std::is_nothrow_default_constructible_v + && std::is_nothrow_default_constructible_v) {} explicit flat_multiset(const Compare& c) : base_type(c) {} diff --git a/headers/flat_hpp/flat_set.hpp b/headers/flat_hpp/flat_set.hpp index 7d53d76..77f3999 100644 --- a/headers/flat_hpp/flat_set.hpp +++ b/headers/flat_hpp/flat_set.hpp @@ -44,8 +44,8 @@ namespace flat_hpp using const_reverse_iterator = typename Container::const_reverse_iterator; public: flat_set() - noexcept(std::is_nothrow_default_constructible::value - && std::is_nothrow_default_constructible::value) {} + noexcept(std::is_nothrow_default_constructible_v + && std::is_nothrow_default_constructible_v) {} explicit flat_set(const Compare& c) : base_type(c) {} diff --git a/untests/flat_map_tests.cpp b/untests/flat_map_tests.cpp index 8c59382..ccad8af 100644 --- a/untests/flat_map_tests.cpp +++ b/untests/flat_map_tests.cpp @@ -14,62 +14,6 @@ using namespace flat_hpp; namespace { - template < typename T > - class dummy_allocator { - public: - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - using value_type = T; - - using propagate_on_container_move_assignment = std::true_type; - using is_always_equal = std::true_type; - - template < typename U > - struct rebind { using other = dummy_allocator; }; - - dummy_allocator() = default; - dummy_allocator(int i) : i(i) {} - - template < typename U > - dummy_allocator(const dummy_allocator& o) noexcept { - i = o.i; - } - - T* allocate(std::size_t n) noexcept { - return static_cast(std::malloc(sizeof(T) * n)); - } - - void deallocate(T* p, std::size_t n) noexcept { - (void)n; - std::free(p); - } - - template < typename U, typename... Args > - void construct(U* p, Args&&... args) { - ::new((void*)p) U(std::forward(args)...); - } - - void destroy(pointer p) { - p->~T(); - } - - int i = 0; - }; - - template < typename T, typename U > - bool operator==(const dummy_allocator&, const dummy_allocator&) noexcept { - return true; - } - - template < typename T, typename U > - bool operator!=(const dummy_allocator& l, const dummy_allocator& r) noexcept { - return !(l == r); - } - template < typename T > class dummy_less { public: @@ -81,6 +25,19 @@ namespace int i = 0; }; + template < typename T > + class dummy_less2 { + dummy_less2() = default; + dummy_less2(dummy_less2&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + + template < typename T > + void swap(dummy_less2&, dummy_less2&) noexcept { + } + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -97,55 +54,56 @@ TEST_CASE("flat_map") { REQUIRE(sizeof(vc) == sizeof(int)); } SECTION("noexcept") { - using alloc_t = dummy_allocator>; + using alloc_t = std::allocator>; using map_t = flat_map, std::vector, alloc_t>>; + using map2_t = flat_map>; static_assert( - std::is_nothrow_default_constructible::value, + std::is_nothrow_default_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_constructible::value, + std::is_nothrow_move_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_assignable::value, + std::is_nothrow_move_assignable_v, "unit test static error"); } SECTION("types") { using map_t = flat_map; static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same>::value, + std::is_same_v>, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same&>::value, + std::is_same_v&>, "unit test static error"); static_assert( - std::is_same&>::value, + std::is_same_v&>, "unit test static error"); static_assert( - std::is_same*>::value, + std::is_same_v*>, "unit test static error"); static_assert( - std::is_same*>::value, + std::is_same_v*>, "unit test static error"); } SECTION("ctors") { - using alloc_t = dummy_allocator< + using alloc_t = std::allocator< std::pair>; using map_t = flat_map< @@ -203,9 +161,9 @@ TEST_CASE("flat_map") { auto s2 = std::move(s1); REQUIRE(s1.empty()); REQUIRE(s2 == map_t{{0,1}, {1,2}}); - auto s3 = map_t(s2, alloc_t(42)); + auto s3 = map_t(s2, alloc_t()); REQUIRE(s2 == s3); - auto s4 = map_t(std::move(s3), alloc_t(21)); + auto s4 = map_t(std::move(s3), alloc_t()); REQUIRE(s3.empty()); REQUIRE(s4 == map_t{{0,1}, {1,2}}); } @@ -268,7 +226,7 @@ TEST_CASE("flat_map") { REQUIRE(s0.capacity() == 3); REQUIRE(s0 == map_t{{1,2},{2,3},{3,4}}); - using alloc2_t = dummy_allocator< + using alloc2_t = std::allocator< std::pair>; using map2_t = flat_map< diff --git a/untests/flat_multimap_tests.cpp b/untests/flat_multimap_tests.cpp index 9f23252..590c59d 100644 --- a/untests/flat_multimap_tests.cpp +++ b/untests/flat_multimap_tests.cpp @@ -14,62 +14,6 @@ using namespace flat_hpp; namespace { - template < typename T > - class dummy_allocator { - public: - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - using value_type = T; - - using propagate_on_container_move_assignment = std::true_type; - using is_always_equal = std::true_type; - - template < typename U > - struct rebind { using other = dummy_allocator; }; - - dummy_allocator() = default; - dummy_allocator(int i) : i(i) {} - - template < typename U > - dummy_allocator(const dummy_allocator& o) noexcept { - i = o.i; - } - - T* allocate(std::size_t n) noexcept { - return static_cast(std::malloc(sizeof(T) * n)); - } - - void deallocate(T* p, std::size_t n) noexcept { - (void)n; - std::free(p); - } - - template < typename U, typename... Args > - void construct(U* p, Args&&... args) { - ::new((void*)p) U(std::forward(args)...); - } - - void destroy(pointer p) { - p->~T(); - } - - int i = 0; - }; - - template < typename T, typename U > - bool operator==(const dummy_allocator&, const dummy_allocator&) noexcept { - return true; - } - - template < typename T, typename U > - bool operator!=(const dummy_allocator& l, const dummy_allocator& r) noexcept { - return !(l == r); - } - template < typename T > class dummy_less { public: @@ -81,6 +25,19 @@ namespace int i = 0; }; + template < typename T > + class dummy_less2 { + dummy_less2() = default; + dummy_less2(dummy_less2&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + + template < typename T > + void swap(dummy_less2&, dummy_less2&) noexcept { + } + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -97,55 +54,56 @@ TEST_CASE("flat_multimap") { REQUIRE(sizeof(vc) == sizeof(int)); } SECTION("noexcept") { - using alloc_t = dummy_allocator>; + using alloc_t = std::allocator>; using map_t = flat_multimap, std::vector, alloc_t>>; + using map2_t = flat_multimap>; static_assert( - std::is_nothrow_default_constructible::value, + std::is_nothrow_default_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_constructible::value, + std::is_nothrow_move_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_assignable::value, + std::is_nothrow_move_assignable_v, "unit test static error"); } SECTION("types") { using map_t = flat_multimap; static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same>::value, + std::is_same_v>, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same&>::value, + std::is_same_v&>, "unit test static error"); static_assert( - std::is_same&>::value, + std::is_same_v&>, "unit test static error"); static_assert( - std::is_same*>::value, + std::is_same_v*>, "unit test static error"); static_assert( - std::is_same*>::value, + std::is_same_v*>, "unit test static error"); } SECTION("ctors") { - using alloc_t = dummy_allocator< + using alloc_t = std::allocator< std::pair>; using map_t = flat_multimap< @@ -203,9 +161,9 @@ TEST_CASE("flat_multimap") { auto s2 = std::move(s1); REQUIRE(s1.empty()); REQUIRE(s2 == map_t{{0,1}, {1,2}}); - auto s3 = map_t(s2, alloc_t(42)); + auto s3 = map_t(s2, alloc_t()); REQUIRE(s2 == s3); - auto s4 = map_t(std::move(s3), alloc_t(21)); + auto s4 = map_t(std::move(s3), alloc_t()); REQUIRE(s3.empty()); REQUIRE(s4 == map_t{{0,1}, {1,2}}); } @@ -268,7 +226,7 @@ TEST_CASE("flat_multimap") { REQUIRE(s0.capacity() == 3); REQUIRE(s0 == map_t{{1,2},{2,3},{3,4}}); - using alloc2_t = dummy_allocator< + using alloc2_t = std::allocator< std::pair>; using map2_t = flat_multimap< diff --git a/untests/flat_multiset_tests.cpp b/untests/flat_multiset_tests.cpp index b3e6bb2..4d9fa0b 100644 --- a/untests/flat_multiset_tests.cpp +++ b/untests/flat_multiset_tests.cpp @@ -14,62 +14,6 @@ using namespace flat_hpp; namespace { - template < typename T > - class dummy_allocator { - public: - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - using value_type = T; - - using propagate_on_container_move_assignment = std::true_type; - using is_always_equal = std::true_type; - - template < typename U > - struct rebind { using other = dummy_allocator; }; - - dummy_allocator() = default; - dummy_allocator(int i) : i(i) {} - - template < typename U > - dummy_allocator(const dummy_allocator& o) noexcept { - i = o.i; - } - - T* allocate(std::size_t n) noexcept { - return static_cast(std::malloc(sizeof(T) * n)); - } - - void deallocate(T* p, std::size_t n) noexcept { - (void)n; - std::free(p); - } - - template < typename U, typename... Args > - void construct(U* p, Args&&... args) { - ::new((void*)p) U(std::forward(args)...); - } - - void destroy(pointer p) { - p->~T(); - } - - int i = 0; - }; - - template < typename T, typename U > - bool operator==(const dummy_allocator&, const dummy_allocator&) noexcept { - return true; - } - - template < typename T, typename U > - bool operator!=(const dummy_allocator& l, const dummy_allocator& r) noexcept { - return !(l == r); - } - template < typename T > class dummy_less { public: @@ -81,6 +25,19 @@ namespace int i = 0; }; + template < typename T > + class dummy_less2 { + dummy_less2() = default; + dummy_less2(dummy_less2&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + + template < typename T > + void swap(dummy_less2&, dummy_less2&) noexcept { + } + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -97,52 +54,53 @@ TEST_CASE("flat_multiset") { REQUIRE(sizeof(vc) == sizeof(int)); } SECTION("noexcept") { - using alloc_t = dummy_allocator; + using alloc_t = std::allocator; using set_t = flat_multiset, std::vector>; + using set2_t = flat_multiset>; static_assert( - std::is_nothrow_default_constructible::value, + std::is_nothrow_default_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_constructible::value, + std::is_nothrow_move_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_assignable::value, + std::is_nothrow_move_assignable_v, "unit test static error"); } SECTION("types") { using set_t = flat_multiset; static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); } SECTION("ctors") { - using alloc_t = dummy_allocator; + using alloc_t = std::allocator; using set_t = flat_multiset, std::vector>; using set2_t = flat_multiset, std::vector>; using vec_t = std::vector; @@ -187,9 +145,9 @@ TEST_CASE("flat_multiset") { auto s2 = std::move(s1); REQUIRE(s1.empty()); REQUIRE(s2 == set_t{0,1,2}); - auto s3 = set_t(s2, alloc_t(42)); + auto s3 = set_t(s2, alloc_t()); REQUIRE(s2 == s3); - auto s4 = set_t(std::move(s3), alloc_t(21)); + auto s4 = set_t(std::move(s3), alloc_t()); REQUIRE(s3.empty()); REQUIRE(s4 == set_t{0,1,2}); } @@ -252,7 +210,7 @@ TEST_CASE("flat_multiset") { REQUIRE(s0.capacity() == 3); REQUIRE(s0 == set_t{1,2,3}); - using alloc2_t = dummy_allocator; + using alloc2_t = std::allocator; using set2_t = flat_multiset< int, diff --git a/untests/flat_set_tests.cpp b/untests/flat_set_tests.cpp index 18f1e80..5419ef1 100644 --- a/untests/flat_set_tests.cpp +++ b/untests/flat_set_tests.cpp @@ -14,62 +14,6 @@ using namespace flat_hpp; namespace { - template < typename T > - class dummy_allocator { - public: - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - using value_type = T; - - using propagate_on_container_move_assignment = std::true_type; - using is_always_equal = std::true_type; - - template < typename U > - struct rebind { using other = dummy_allocator; }; - - dummy_allocator() = default; - dummy_allocator(int i) : i(i) {} - - template < typename U > - dummy_allocator(const dummy_allocator& o) noexcept { - i = o.i; - } - - T* allocate(std::size_t n) noexcept { - return static_cast(std::malloc(sizeof(T) * n)); - } - - void deallocate(T* p, std::size_t n) noexcept { - (void)n; - std::free(p); - } - - template < typename U, typename... Args > - void construct(U* p, Args&&... args) { - ::new((void*)p) U(std::forward(args)...); - } - - void destroy(pointer p) { - p->~T(); - } - - int i = 0; - }; - - template < typename T, typename U > - bool operator==(const dummy_allocator&, const dummy_allocator&) noexcept { - return true; - } - - template < typename T, typename U > - bool operator!=(const dummy_allocator& l, const dummy_allocator& r) noexcept { - return !(l == r); - } - template < typename T > class dummy_less { public: @@ -81,6 +25,19 @@ namespace int i = 0; }; + template < typename T > + class dummy_less2 { + dummy_less2() = default; + dummy_less2(dummy_less2&&) noexcept(false) {} + bool operator()(const T& l, const T& r) const { + return l < r; + } + }; + + template < typename T > + void swap(dummy_less2&, dummy_less2&) noexcept { + } + template < typename T > constexpr std::add_const_t& my_as_const(T& t) noexcept { return t; @@ -97,52 +54,53 @@ TEST_CASE("flat_set") { REQUIRE(sizeof(vc) == sizeof(int)); } SECTION("noexcept") { - using alloc_t = dummy_allocator; + using alloc_t = std::allocator; using set_t = flat_set, std::vector>; + using set2_t = flat_set>; static_assert( - std::is_nothrow_default_constructible::value, + std::is_nothrow_default_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_constructible::value, + std::is_nothrow_move_constructible_v, "unit test static error"); static_assert( - std::is_nothrow_move_assignable::value, + std::is_nothrow_move_assignable_v, "unit test static error"); } SECTION("types") { using set_t = flat_set; static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); static_assert( - std::is_same::value, + std::is_same_v, "unit test static error"); } SECTION("ctors") { - using alloc_t = dummy_allocator; + using alloc_t = std::allocator; using set_t = flat_set, std::vector>; using set2_t = flat_set, std::vector>; using vec_t = std::vector; @@ -187,9 +145,9 @@ TEST_CASE("flat_set") { auto s2 = std::move(s1); REQUIRE(s1.empty()); REQUIRE(s2 == set_t{0,1,2}); - auto s3 = set_t(s2, alloc_t(42)); + auto s3 = set_t(s2, alloc_t()); REQUIRE(s2 == s3); - auto s4 = set_t(std::move(s3), alloc_t(21)); + auto s4 = set_t(std::move(s3), alloc_t()); REQUIRE(s3.empty()); REQUIRE(s4 == set_t{0,1,2}); } @@ -252,7 +210,7 @@ TEST_CASE("flat_set") { REQUIRE(s0.capacity() == 3); REQUIRE(s0 == set_t{1,2,3}); - using alloc2_t = dummy_allocator; + using alloc2_t = std::allocator; using set2_t = flat_set< int,