From cdae59eb5bafdbbffca45873f72502c1fbe7e2b9 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 30 Nov 2020 01:53:54 +0700 Subject: [PATCH] add deduction guides #15 --- headers/flat.hpp/detail/is_allocator.hpp | 24 ++++++ headers/flat.hpp/detail/iter_traits.hpp | 22 +++++ headers/flat.hpp/flat_fwd.hpp | 15 ++-- headers/flat.hpp/flat_map.hpp | 96 +++++++++++++++++++++ headers/flat.hpp/flat_multimap.hpp | 96 +++++++++++++++++++++ headers/flat.hpp/flat_multiset.hpp | 90 ++++++++++++++++++++ headers/flat.hpp/flat_set.hpp | 90 ++++++++++++++++++++ untests/flat_map_tests.cpp | 103 +++++++++++++++++++++++ untests/flat_multimap_tests.cpp | 103 +++++++++++++++++++++++ untests/flat_multiset_tests.cpp | 74 ++++++++++++++++ untests/flat_set_tests.cpp | 74 ++++++++++++++++ 11 files changed, 781 insertions(+), 6 deletions(-) create mode 100644 headers/flat.hpp/detail/is_allocator.hpp create mode 100644 headers/flat.hpp/detail/iter_traits.hpp diff --git a/headers/flat.hpp/detail/is_allocator.hpp b/headers/flat.hpp/detail/is_allocator.hpp new file mode 100644 index 0000000..2a42f4c --- /dev/null +++ b/headers/flat.hpp/detail/is_allocator.hpp @@ -0,0 +1,24 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/flat.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include +#include + +namespace flat_hpp::detail +{ + template < typename Allocator, typename = void > + struct is_allocator : std::false_type {}; + + template < typename Allocator > + struct is_allocator().deallocate( + std::declval().allocate(std::size_t{1}), + std::size_t{1})) + >> : std::true_type {}; +} diff --git a/headers/flat.hpp/detail/iter_traits.hpp b/headers/flat.hpp/detail/iter_traits.hpp new file mode 100644 index 0000000..d6c073c --- /dev/null +++ b/headers/flat.hpp/detail/iter_traits.hpp @@ -0,0 +1,22 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/flat.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include +#include + +namespace flat_hpp::detail +{ + template < typename InputIter > + using iter_value_type = typename std::iterator_traits::value_type; + + template < typename InputIter > + using iter_key_type = std::remove_const_t::first_type>; + + template < typename InputIter > + using iter_mapped_type = typename iter_value_type::second_type; +} diff --git a/headers/flat.hpp/flat_fwd.hpp b/headers/flat.hpp/flat_fwd.hpp index 3d6f73e..790e34c 100644 --- a/headers/flat.hpp/flat_fwd.hpp +++ b/headers/flat.hpp/flat_fwd.hpp @@ -6,18 +6,21 @@ #pragma once -#include -#include -#include #include +#include #include -#include #include +#include +#include +#include +#include -#include "detail/is_sorted.hpp" #include "detail/eq_compare.hpp" -#include "detail/pair_compare.hpp" +#include "detail/is_allocator.hpp" +#include "detail/is_sorted.hpp" #include "detail/is_transparent.hpp" +#include "detail/iter_traits.hpp" +#include "detail/pair_compare.hpp" namespace flat_hpp { diff --git a/headers/flat.hpp/flat_map.hpp b/headers/flat.hpp/flat_map.hpp index a74910e..8a11a26 100644 --- a/headers/flat.hpp/flat_map.hpp +++ b/headers/flat.hpp/flat_map.hpp @@ -709,6 +709,102 @@ namespace flat_hpp }; } +namespace flat_hpp +{ + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_map(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, detail::iter_mapped_type>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, detail::iter_mapped_type>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, detail::iter_mapped_type>; + + // + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_map, detail::iter_mapped_type, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_map, detail::iter_mapped_type, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_map, detail::iter_mapped_type, Compare>; + + // + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_map(std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, Value>; + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_range_t, std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, Value>; + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_unique_range_t, std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_map, Value>; + + // + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_map, Value, Compare>; + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_range_t, std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_map, Value, Compare>; + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_map(sorted_unique_range_t, std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_map, Value, Compare>; +} + namespace flat_hpp { template < typename Key diff --git a/headers/flat.hpp/flat_multimap.hpp b/headers/flat.hpp/flat_multimap.hpp index 0292b02..486494c 100644 --- a/headers/flat.hpp/flat_multimap.hpp +++ b/headers/flat.hpp/flat_multimap.hpp @@ -594,6 +594,102 @@ namespace flat_hpp }; } +namespace flat_hpp +{ + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multimap(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, detail::iter_mapped_type>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, detail::iter_mapped_type>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, detail::iter_mapped_type>; + + // + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, detail::iter_mapped_type, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, detail::iter_mapped_type, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator>, + detail::iter_mapped_type>> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, detail::iter_mapped_type, Compare>; + + // + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_multimap(std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, Value>; + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_range_t, std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, Value>; + + template < typename Key, typename Value + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_unique_range_t, std::initializer_list>, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multimap, Value>; + + // + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, Value, Compare>; + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_range_t, std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, Value, Compare>; + + template < typename Key, typename Value + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multimap(sorted_unique_range_t, std::initializer_list>, Compare = Compare(), Allocator = Allocator()) + -> flat_multimap, Value, Compare>; +} + namespace flat_hpp { template < typename Key diff --git a/headers/flat.hpp/flat_multiset.hpp b/headers/flat.hpp/flat_multiset.hpp index cc5a2a3..fb3414e 100644 --- a/headers/flat.hpp/flat_multiset.hpp +++ b/headers/flat.hpp/flat_multiset.hpp @@ -510,6 +510,96 @@ namespace flat_hpp }; } +namespace flat_hpp +{ + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset>; + + // + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset, Compare>; + + // + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset; + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_range_t, std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset; + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_unique_range_t, std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_multiset; + + // + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset; + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_range_t, std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset; + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_multiset(sorted_unique_range_t, std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_multiset; +} + namespace flat_hpp { template < typename Key diff --git a/headers/flat.hpp/flat_set.hpp b/headers/flat.hpp/flat_set.hpp index 7b6dc4b..e590c70 100644 --- a/headers/flat.hpp/flat_set.hpp +++ b/headers/flat.hpp/flat_set.hpp @@ -583,6 +583,96 @@ namespace flat_hpp }; } +namespace flat_hpp +{ + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_set(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set>; + + template < typename InputIter, typename Allocator + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set>; + + // + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_set, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_set, Compare>; + + template < typename InputIter + , typename Compare = std::less> + , typename Allocator = std::allocator> + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator()) + -> flat_set, Compare>; + + // + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_set(std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set; + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_range_t, std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set; + + template < typename Key + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_unique_range_t, std::initializer_list, Allocator, int* msvc_2017_workaround = nullptr) + -> flat_set; + + // + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_set; + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_range_t, std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_set; + + template < typename Key + , typename Compare = std::less + , typename Allocator = std::allocator + , std::enable_if_t::value, int> = 0 + , std::enable_if_t::value, int> = 0 > + flat_set(sorted_unique_range_t, std::initializer_list, Compare = Compare(), Allocator = Allocator()) + -> flat_set; +} + namespace flat_hpp { template < typename Key diff --git a/untests/flat_map_tests.cpp b/untests/flat_map_tests.cpp index eb2b05a..7a4d455 100644 --- a/untests/flat_map_tests.cpp +++ b/untests/flat_map_tests.cpp @@ -57,6 +57,109 @@ namespace } TEST_CASE("flat_map") { + SUBCASE("guides") { + { + std::vector> vs; + + auto s0 = flat_map(vs.begin(), vs.end()); + auto s1 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end()); + auto s2 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end()); + + auto s3 = flat_map(vs.begin(), vs.end(), std::less()); + auto s4 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less()); + auto s5 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less()); + + auto s6 = flat_map(vs.begin(), vs.end(), std::allocator()); + auto s7 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator()); + auto s8 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator()); + + auto s9 = flat_map(vs.begin(), vs.end(), std::less(), std::allocator()); + auto s10 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less(), std::allocator()); + auto s11 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}); + auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}); + auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::less()); + auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less()); + auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + } SUBCASE("detail") { STATIC_REQUIRE(detail::is_transparent, int>::value); STATIC_REQUIRE_FALSE(detail::is_transparent, int>::value); diff --git a/untests/flat_multimap_tests.cpp b/untests/flat_multimap_tests.cpp index f1050c5..3a33260 100644 --- a/untests/flat_multimap_tests.cpp +++ b/untests/flat_multimap_tests.cpp @@ -57,6 +57,109 @@ namespace } TEST_CASE("flat_multimap") { + SUBCASE("guides") { + { + std::vector> vs; + + auto s0 = flat_multimap(vs.begin(), vs.end()); + auto s1 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end()); + auto s2 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end()); + + auto s3 = flat_multimap(vs.begin(), vs.end(), std::less()); + auto s4 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less()); + auto s5 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less()); + + auto s6 = flat_multimap(vs.begin(), vs.end(), std::allocator()); + auto s7 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator()); + auto s8 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator()); + + auto s9 = flat_multimap(vs.begin(), vs.end(), std::less(), std::allocator()); + auto s10 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less(), std::allocator()); + auto s11 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}); + auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}); + auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::less()); + auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less()); + auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + } SUBCASE("detail") { STATIC_REQUIRE(detail::is_transparent, int>::value); STATIC_REQUIRE_FALSE(detail::is_transparent, int>::value); diff --git a/untests/flat_multiset_tests.cpp b/untests/flat_multiset_tests.cpp index c82e8a9..8b71d39 100644 --- a/untests/flat_multiset_tests.cpp +++ b/untests/flat_multiset_tests.cpp @@ -57,6 +57,80 @@ namespace } TEST_CASE("flat_multiset") { + SUBCASE("guides") { + { + std::vector vs; + + auto s0 = flat_multiset(vs.begin(), vs.end()); + auto s1 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end()); + auto s2 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end()); + + auto s3 = flat_multiset(vs.begin(), vs.end(), std::less()); + auto s4 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less()); + auto s5 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less()); + + auto s6 = flat_multiset(vs.begin(), vs.end(), std::allocator()); + auto s7 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator()); + auto s8 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator()); + + auto s9 = flat_multiset(vs.begin(), vs.end(), std::less(), std::allocator()); + auto s10 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less(), std::allocator()); + auto s11 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multiset({1, 2}); + auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}); + auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multiset({1, 2}, std::less()); + auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::less()); + auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::less()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multiset({1, 2}, std::allocator()); + auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::allocator()); + auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_multiset({1, 2}, std::less(), std::allocator()); + auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::less(), std::allocator()); + auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + } SUBCASE("detail") { STATIC_REQUIRE(detail::is_transparent, int>::value); STATIC_REQUIRE_FALSE(detail::is_transparent, int>::value); diff --git a/untests/flat_set_tests.cpp b/untests/flat_set_tests.cpp index e86113d..1a72d28 100644 --- a/untests/flat_set_tests.cpp +++ b/untests/flat_set_tests.cpp @@ -57,6 +57,80 @@ namespace } TEST_CASE("flat_set") { + SUBCASE("guides") { + { + std::vector vs; + + auto s0 = flat_set(vs.begin(), vs.end()); + auto s1 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end()); + auto s2 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end()); + + auto s3 = flat_set(vs.begin(), vs.end(), std::less()); + auto s4 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less()); + auto s5 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less()); + + auto s6 = flat_set(vs.begin(), vs.end(), std::allocator()); + auto s7 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator()); + auto s8 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator()); + + auto s9 = flat_set(vs.begin(), vs.end(), std::less(), std::allocator()); + auto s10 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less(), std::allocator()); + auto s11 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_set({1, 2}); + auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}); + auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_set({1, 2}, std::less()); + auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::less()); + auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::less()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_set({1, 2}, std::allocator()); + auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::allocator()); + auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + + { + auto s1 = flat_set({1, 2}, std::less(), std::allocator()); + auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::less(), std::allocator()); + auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::less(), std::allocator()); + + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + STATIC_REQUIRE(std::is_same_v); + } + } SUBCASE("detail") { STATIC_REQUIRE(detail::is_transparent, int>::value); STATIC_REQUIRE_FALSE(detail::is_transparent, int>::value);