From c923070a942b0b6547394d2a6c6de43326ebeebc Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Fri, 17 Feb 2023 11:58:49 -0500 Subject: [PATCH] Rename to `sg14::` and add a real README; let's do this! --- .travis.yml | 1 + README.md | 219 ++++++++- benchmarks/CMakeLists.txt | 2 +- benchmarks/dummy_bench.cpp | 0 benchmarks/hive_bench.cpp | 185 ------- include/sg14/algorithm_ext.h | 283 +++++------ include/sg14/flat_map.h | 8 +- include/sg14/flat_set.h | 4 +- include/sg14/{plf_hive.h => hive.h} | 147 +++--- include/sg14/inplace_function.h | 4 +- include/sg14/ring.h | 539 --------------------- include/sg14/ring_span.h | 520 ++++++++++++++++++++ include/sg14/slot_map.h | 14 +- test/CMakeLists.txt | 2 +- test/flat_map_test.cpp | 102 ++-- test/flat_set_test.cpp | 42 +- test/hive_test.cpp | 318 ++++++------ test/inplace_function_test.cpp | 158 +++--- test/{ring_test.cpp => ring_span_test.cpp} | 2 +- test/slot_map_test.cpp | 26 +- test/uninitialized_test.cpp | 12 +- test/unstable_remove_test.cpp | 6 +- 22 files changed, 1271 insertions(+), 1323 deletions(-) create mode 100644 benchmarks/dummy_bench.cpp delete mode 100644 benchmarks/hive_bench.cpp rename include/sg14/{plf_hive.h => hive.h} (97%) delete mode 100644 include/sg14/ring.h create mode 100644 include/sg14/ring_span.h rename test/{ring_test.cpp => ring_span_test.cpp} (99%) diff --git a/.travis.yml b/.travis.yml index dd378b39..4ee576d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -134,6 +134,7 @@ matrix: script: - mkdir build && cd build && cmake .. && cmake --build . && ./bin/utest + - mkdir build && cd build && cmake .. -DCMAKE_CXX_STANDARD=14 && cmake --build . && ./bin/utest notifications: email: diff --git a/README.md b/README.md index 54a74e78..9490edcb 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,216 @@ # SG14 -[![Build Status](https://travis-ci.org/WG21-SG14/SG14.svg?branch=master)](https://travis-ci.org/WG21-SG14/SG14) +[![Build Status](https://travis-ci.org/Quuxplusone/SG14.svg?branch=master)](https://travis-ci.org/Quuxplusone/SG14) -A library for Study Group 14 of Working Group 21 (C++) +A library of containers and algorithms pioneered by the ISO C++ Committee's +"Low-Latency and Embedded" study group (SG14). For more information on +SG14, see [the mailing list](http://lists.isocpp.org/mailman/listinfo.cgi/sg14). -/docs - Documentation for implementations without proposals, or supplementary documentation which does not easily fit within a proposal. -/docs/proposals - C++ standard proposals. +## What's included -/include - Source files for implementations. +### Efficient algorithms -/test - Individual tests for implementations. +``` +#include -http://lists.isocpp.org/mailman/listinfo.cgi/sg14 for more information +FwdIt sg14::unstable_remove(FwdIt first, FwdIt last, const T& value); +FwdIt sg14::unstable_remove_if(FwdIt first, FwdIt last, Pred pred); +``` -## Build Instructions -Clone the repo. Navigate to the folder in your favorite terminal. +`sg14::unstable_remove_if` is like `std::remove_if`, but doesn't preserve the relative order +of the non-removed elements. It doesn't "shuffle elements leftward"; it simply "replaces each +removed element with `*--last`." These algorithms were proposed in +[P0041](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0041r0.html). -`mkdir build && cd build` +Note that `std::erase_if(lst, Pred)` is more efficient than +`lst.erase(sg14::unstable_remove_if(lst, Pred), lst.end())` when +`lst` is a `std::list`; therefore P0041 also proposed a set of +`sg14::unstable_erase_if` overloads, which we don't provide, yet. -### Windows -`cmake .. -A x64 && cmake --build . && bin\utest.exe` +``` +FwdIt sg14::uninitialized_move(It first, Sent last, FwdIt d_first); +FwdIt sg14::uninitialized_value_construct(FwdIt first, Sent last); +FwdIt sg14::uninitialized_default_construct(FwdIt first, Sent last); +void sg14::destroy(FwdIt, FwdIt); +``` -### Unixes -`cmake .. && cmake --build . && ./bin/utest` +These algorithms were proposed in +[P0040](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0040r3.html) +and adopted into C++17. The `sg14` versions are slightly more general (they take +iterator-sentinel pairs) and portable back to C++11, but in C++17 you should +use the `std` versions, please. + +### Flat associative container adaptors + +``` +#include +#include + +template, class Cont = vector> +class sg14::flat_set; + +template, class KCont = vector, class VCont = vector> +class sg14::flat_map; +``` + +`sg14::flat_set` is a drop-in replacement for `std::set`, but under the hood it uses +a vector to store its data in sorted order, instead of being a node-based tree data structure. +These container adaptors were proposed in +[P1222](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1222r4.pdf) (`flat_set`) and +[P0429](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0429r9.pdf) (`flat_map`), +and adopted into C++23. The `sg14` versions are portable back to C++14. + +C++23 also provides `flat_multimap` and `flat_multiset`, which we don't provide. + +Boost also provides all four adaptors; see [`boost::container::flat_set`](https://www.boost.org/doc/libs/1_81_0/doc/html/container/non_standard_containers.html#container.non_standard_containers.flat_xxx). + +### In-place type-erased types + +``` +#include + +template +class sg14::inplace_function; +``` + +The standard `std::function` has a "small buffer optimization" so that small callables +(such as lambdas that capture only a few things) can be stored inside the memory footprint of +the `function` object instead of on the heap. + +`sg14::inplace_function` is a drop-in replacement for `std::function`, +except that it is compile-time-constrained to hold _only_ callables that can fit into its +small buffer. Types that are too large, or too aligned, are simply not convertible to +`sg14::inplace_function` — you'll get a compile-time error instead. + +The size and alignment of the small buffer are configurable via template parameters. + +The C++11 `std::function` has a const-correctness issue: + +``` + auto lam = [i=0]() mutable { return ++i; }; + const std::function f = lam; + assert(f() == 1); + assert(f() == 2); +``` + +C++23's `std::move_only_function` and the proposed `std::function_ref` fix this const-correctness issue +by making `operator()` take on the cvref-qualifiers of the `Signature` type; and `sg14::inplace_function` +follows that same design. For example: + +``` + auto lam = [i=0]() mutable { return ++i; }; + const sg14::inplace_function f1 = lam; + f1(); // does not compile: operator() is a non-const member function + + sg14::function f2 = lam; + f2(); // OK: operator() mutates f2, as expected + + const sg14::function f3 = lam; // does not compile: lam is not const-callable + f3(); // would be OK: operator() is a const member function +``` + +In practice, most of your uses of `std::function` should be replaced not with +`sg14::inplace_function` but rather with `sg14::inplace_function`. + +### Circular `ring_span` + +``` +#include + +template> +class sg14::ring_span; +``` + +`sg14::ring_span` is a "view plus metadata" type — not a pure container adaptor like `std::queue`, +but not a pure view type like C++20 `std::span`. It sits on top of a fixed-size contiguous range +(such as a C array), treats the range as a circular buffer, and exposes a `deque`-like API. + +`sg14::ring_span` is not a _concurrent queue_; it is only as thread-safe as `std::vector`, +which is to say, it is not thread-safe at all. + +Copying a `sg14::ring_span` gives you a second `ring_span` object, with its own head and tail pointers, +but referencing the same underlying range. You probably don't want to do this; pass `ring_span` by +reference or by move, if you pass them around at all. + +The `Popper` policy parameter controls whether `r.pop_front()` should return a copy of the popped +element; a move of the popped element; `void` (thus simulating `std::queue::pop()`); or something more +complicated. The default behavior is to move-from the popped element. + +This adaptor was proposed in +[P0059](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0059r4.pdf). +Martin Moene has another implementation at [martinmoene/ring-span-lite](https://github.com/martinmoene/ring-span-lite). + +### `slot_map` + +``` +#include + +template, template class Cont = vector> +class sg14::slot_map; +``` + +The objects in a `slot_map` are stored in a random-access sequence container of type `Cont`, +and use that container's iterators, just like `sg14::flat_set` does. +`slot_map::erase` uses the equivalent of `sg14::unstable_remove` on that container, so it takes O(1) time +and invalidates pointers and iterators. +But `slot_map::insert` returns a value of type `key_type`, not `iterator`, and keys (unlike iterators) +remain stable over insertion and erasure. Use `slot_map::find` to convert a `key_type` +back into a dereferenceable `iterator`: + +``` + sg14::slot_map sm = {1, 2, 3, 4, 5}; + sg14::slot_map::key_type key = sm.insert(6); + assert(sm.find(key) == sm.begin() + 5); + sm.erase(sm.begin() + 2); // invalidates pointers and iterators, 6 moves to the middle + assert(sm.find(key) == sm.begin() + 2); + assert(sm.at(key) == 6); // keys are not invalidated + sm.erase(sm.begin() + 2); + assert(sm.find(key) == sm.end()); +``` + +This container adaptor was proposed in +[P0661](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0661r0.pdf). + +### `hive` (C++17 and later) + +``` +#include + +template> +class hive; +``` + +A `hive` is superficially similar to a `std::deque`: it stores its elements in +piecewise contiguous blocks. But where a `deque` manages an array of fixed-size blocks +that never contain "holes" (except for spare capacity at either end), a `hive` manages +a linked list of variable-sized blocks that can contain "holes." Inserting into a `hive` +will go back and fill holes before it allocates new blocks. This means that `hive`, +like `sg14::slot_map`, is not a sequence container (you cannot choose where to insert +elements) but also not an associative container (you cannot quickly find the element with +a specific value). Its value proposition is that pointers remain stable over insertion +and erasure. + +`sg14::hive` is directly derived from Matt Bentley's +[`plf::hive`](https://github.com/mattreecebentley/plf_hive), +formerly known as +[`plf::colony`](https://github.com/mattreecebentley/plf_colony). `hive` was proposed in +[P0447](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0447r20.html). + +## How to build + +``` +git clone git@github.com:Quuxplusone/SG14.git +cd SG14 +mkdir build +cd build +cmake .. && make && bin/utest +``` + +To test a particular C++ standard version, set `CMAKE_CXX_STANDARD` at build time: + +``` +cmake .. -DCMAKE_CXX_STANDARD=17 && make && bin/utest +``` + +Each individual header file is deliberately standalone; you can copy just the one `.h` file +into your project and it should work fine with no other dependencies (except the C++ standard library). diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index f691f09c..21039431 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(benchmark REQUIRED) set(BENCH_SOURCE_FILES - hive_bench.cpp + dummy_bench.cpp ) set(BENCH_NAME ubench) diff --git a/benchmarks/dummy_bench.cpp b/benchmarks/dummy_bench.cpp new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/hive_bench.cpp b/benchmarks/hive_bench.cpp deleted file mode 100644 index e050609c..00000000 --- a/benchmarks/hive_bench.cpp +++ /dev/null @@ -1,185 +0,0 @@ - -// You can omit this line, but then we'll spend most of our time in std::next. -#define PLF_HIVE_RANDOM_ACCESS_ITERATORS 1 - -#define PLF_HIVE_P2596 0 -#include -#undef PLF_HIVE_P2596 - -#undef PLF_HIVE_H -#define plf p2596 -#define PLF_HIVE_P2596 1 -#include -#undef PLF_HIVE_P2596 -#undef plf - -#if __cplusplus >= 202002L -#undef PLF_HIVE_H -#define plf matt -#undef __cpp_lib_hive -#include "../../plf_hive/plf_hive.h" -#undef plf -#endif // __cplusplus >= 202002L - -#include - -struct xoshiro256ss { - using u64 = unsigned long long; - u64 s[4] {}; - - static constexpr u64 splitmix64(u64& x) { - u64 z = (x += 0x9e3779b97f4a7c15uLL); - z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9uLL; - z = (z ^ (z >> 27)) * 0x94d049bb133111ebuLL; - return z ^ (z >> 31); - } - - constexpr explicit xoshiro256ss() : xoshiro256ss(0) {} - - constexpr explicit xoshiro256ss(u64 seed) { - s[0] = splitmix64(seed); - s[1] = splitmix64(seed); - s[2] = splitmix64(seed); - s[3] = splitmix64(seed); - } - - using result_type = u64; - static constexpr u64 min() { return 0; } - static constexpr u64 max() { return u64(-1); } - - static constexpr u64 rotl(u64 x, int k) { - return (x << k) | (x >> (64 - k)); - } - - constexpr u64 operator()() { - u64 result = rotl(s[1] * 5, 7) * 9; - u64 t = s[1] << 17; - s[2] ^= s[0]; - s[3] ^= s[1]; - s[1] ^= s[2]; - s[0] ^= s[3]; - s[2] ^= t; - s[3] = rotl(s[3], 45); - return result; - } -}; - -#define N 1000 - -#if __cplusplus >= 202002L && N < 256 -static void BM_PlfStackIssue1_MattSmart(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - matt::hive h; - h.reshape({N, N}); - - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_MattSmart); - -static void BM_PlfStackIssue1_MattNaive(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - matt::hive h; - - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_MattNaive); -#endif - -static void BM_PlfStackIssue1_OldSmart(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - plf::hive h; - h.reshape({N, N}); - - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_OldSmart); - -static void BM_PlfStackIssue1_OldNaive(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - plf::hive h; - - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_OldNaive); - -static void BM_PlfStackIssue1_NewSmart(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - p2596::hive h; - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - if (h.capacity() == h.size()) { - p2596::hive temp; - temp.reserve(N); - h.splice(temp); - } - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_NewSmart); - -static void BM_PlfStackIssue1_NewNaive(benchmark::State& state) { - int fake_input[N] = {}; - xoshiro256ss g; - p2596::hive h; - - for (auto _ : state) { - for (int t = 0; t < 100; ++t) { - if (g() % 2 || h.empty()) { - h.insert(fake_input, fake_input + N); - } else { - h.erase(h.begin(), std::next(h.begin(), N)); - } - } - } - benchmark::DoNotOptimize(h); -} -BENCHMARK(BM_PlfStackIssue1_NewNaive); - -BENCHMARK_MAIN(); diff --git a/include/sg14/algorithm_ext.h b/include/sg14/algorithm_ext.h index a24ae832..08ca75b1 100644 --- a/include/sg14/algorithm_ext.h +++ b/include/sg14/algorithm_ext.h @@ -5,175 +5,128 @@ #include #include -namespace stdext -{ - template - void destruct(ForwardIterator begin, ForwardIterator end) - { - typedef typename std::iterator_traits::value_type _T; - while (begin != end) - { - begin->~_T(); - ++begin; - } - } +namespace sg14 { +template +void destroy(FwdIt begin, FwdIt end) { + typedef typename std::iterator_traits::value_type T; + while (begin != end) { + begin->~T(); + ++begin; + } +} - template - FwdIt uninitialized_move(SrcIt SrcBegin, Sentinel SrcEnd, FwdIt Dst) - { - FwdIt current = Dst; - try - { - while (SrcBegin != SrcEnd) - { - ::new (static_cast(std::addressof(*current))) typename std::iterator_traits::value_type(std::move(*SrcBegin)); - ++current; - ++SrcBegin; - } - return current; - } - catch (...) - { - destruct(Dst, current); - throw; - } - } - - template - FwdIt uninitialized_value_construct(FwdIt first, Sentinel last) - { - FwdIt current = first; - try - { - while (current != last) - { - ::new (static_cast(std::addressof(*current))) typename std::iterator_traits::value_type(); - ++current; - } - return current; - } - catch (...) - { - destruct(first, current); - throw; - } - } - - template - FwdIt uninitialized_default_construct(FwdIt first, Sentinel last) - { - FwdIt current = first; - try - { - while (current != last) - { - ::new (static_cast(std::addressof(*current))) typename std::iterator_traits::value_type; - ++current; - } - return current; - } - catch (...) - { - destruct(first, current); - throw; - } - } - - template - BidirIt unstable_remove_if(BidirIt first, BidirIt last, UnaryPredicate p) - { - while (true) { - // Find the first instance of "p"... - while (true) { - if (first == last) { - return first; - } - if (p(*first)) { - break; - } - ++first; - } - // ...and the last instance of "not p"... - while (true) { - --last; - if (first == last) { - return first; - } - if (!p(*last)) { - break; - } - } - // ...and move the latter over top of the former. - *first = std::move(*last); - ++first; - } - } +template +FwdIt uninitialized_move(SrcIt SrcBegin, Sentinel SrcEnd, FwdIt Dst) { + typedef typename std::iterator_traits::value_type T; + FwdIt current = Dst; + try { + while (SrcBegin != SrcEnd) { + ::new (static_cast(std::addressof(*current))) T(std::move(*SrcBegin)); + ++current; + ++SrcBegin; + } + return current; + } catch (...) { + sg14::destroy(Dst, current); + throw; + } +} - template - BidirIt unstable_remove(BidirIt first, BidirIt last, const Val& v) - { - while (true) { - // Find the first instance of "v"... - while (true) { - if (first == last) { - return first; - } - if (*first == v) { - break; - } - ++first; - } - // ...and the last instance of "not v"... - while (true) { - --last; - if (first == last) { - return first; - } - if (!(*last == v)) { - break; - } - } - // ...and move the latter over top of the former. - *first = std::move(*last); - ++first; - } - } +template +FwdIt uninitialized_value_construct(FwdIt first, Sentinel last) { + typedef typename std::iterator_traits::value_type T; + FwdIt current = first; + try { + while (current != last) { + ::new (static_cast(std::addressof(*current))) T(); + ++current; + } + return current; + } catch (...) { + sg14::destroy(first, current); + throw; + } +} +template +FwdIt uninitialized_default_construct(FwdIt first, Sentinel last) { + typedef typename std::iterator_traits::value_type T; + FwdIt current = first; + try { + while (current != last) { + ::new (static_cast(std::addressof(*current))) T; + ++current; + } + return current; + } catch (...) { + sg14::destroy(first, current); + throw; + } +} - //this exists as a point of reference for providing a stable comparison vs unstable_remove_if - template - BidirIt partition(BidirIt first, BidirIt last, UnaryPredicate p) - { - while (true) { - while ((first != last) && p(*first)) { - ++first; - } - if (first == last) break; - --last; - while ((first != last) && !p(*last)) { - --last; - } - if (first == last) break; - std::iter_swap(first, last); - ++first; - } - return first; - } +template +#if __cplusplus >= 201703L +[[nodiscard]] +#endif +BidirIt unstable_remove_if(BidirIt first, BidirIt last, UnaryPredicate p) { + while (true) { + // Find the first instance of "p"... + while (true) { + if (first == last) { + return first; + } + if (p(*first)) { + break; + } + ++first; + } + // ...and the last instance of "not p"... + while (true) { + --last; + if (first == last) { + return first; + } + if (!p(*last)) { + break; + } + } + // ...and move the latter over top of the former. + *first = std::move(*last); + ++first; + } +} - //this exists as a point of reference for providing a stable comparison vs unstable_remove_if - template - ForwardIt remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p) - { - first = std::find_if(first, last, p); - if (first != last) { - for (ForwardIt i = first; ++i != last; ) { - if (!p(*i)) { - *first = std::move(*i); - ++first; - } - } - } - return first; - } +template +#if __cplusplus >= 201703L +[[nodiscard]] +#endif +BidirIt unstable_remove(BidirIt first, BidirIt last, const Val& v) { + while (true) { + // Find the first instance of "v"... + while (true) { + if (first == last) { + return first; + } + if (*first == v) { + break; + } + ++first; + } + // ...and the last instance of "not v"... + while (true) { + --last; + if (first == last) { + return first; + } + if (!(*last == v)) { + break; + } + } + // ...and move the latter over top of the former. + *first = std::move(*last); + ++first; + } } + +} // namespace sg14 diff --git a/include/sg14/flat_map.h b/include/sg14/flat_map.h index d6f0f162..20e4755b 100644 --- a/include/sg14/flat_map.h +++ b/include/sg14/flat_map.h @@ -36,7 +36,7 @@ #include #include -namespace stdext { +namespace sg14 { namespace flatmap_detail { template struct qualifies_as_range : std::false_type {}; @@ -646,7 +646,7 @@ class flat_map { template::value>::type> - void insert(stdext::sorted_unique_t, InputIterator first, InputIterator last) { + void insert(sg14::sorted_unique_t, InputIterator first, InputIterator last) { // TODO: if InputIterator is bidirectional, this loop should (go backward??) // TODO: if we're inserting lots of elements, stick them at the end and then sort auto it = begin(); @@ -667,7 +667,7 @@ class flat_map { this->insert(il.begin(), il.end()); } - void insert(stdext::sorted_unique_t s, std::initializer_list il) { + void insert(sg14::sorted_unique_t s, std::initializer_list il) { this->insert(s, il.begin(), il.end()); } @@ -1219,4 +1219,4 @@ flat_map(sorted_unique_t, std::initializer_list>, Alloca #endif -} // namespace stdext +} // namespace sg14 diff --git a/include/sg14/flat_set.h b/include/sg14/flat_set.h index 2d88b23b..af1c166c 100644 --- a/include/sg14/flat_set.h +++ b/include/sg14/flat_set.h @@ -36,7 +36,7 @@ #include #include -namespace stdext { +namespace sg14 { namespace flatset_detail { template struct qualifies_as_range : std::false_type {}; @@ -759,4 +759,4 @@ flat_set(InputIterator, InputIterator, Allocator, int=0/*to please MSVC*/) #endif -} // namespace stdext +} // namespace sg14 diff --git a/include/sg14/plf_hive.h b/include/sg14/hive.h similarity index 97% rename from include/sg14/plf_hive.h rename to include/sg14/hive.h index bea1b6f6..7b453503 100644 --- a/include/sg14/plf_hive.h +++ b/include/sg14/hive.h @@ -19,27 +19,26 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -#ifndef PLF_HIVE_H -#define PLF_HIVE_H +#pragma once -#ifndef PLF_HIVE_P2596 - #define PLF_HIVE_P2596 1 +#ifndef SG14_HIVE_P2596 + #define SG14_HIVE_P2596 1 #endif -#ifndef PLF_HIVE_RANDOM_ACCESS_ITERATORS - #define PLF_HIVE_RANDOM_ACCESS_ITERATORS 0 +#ifndef SG14_HIVE_RANDOM_ACCESS_ITERATORS + #define SG14_HIVE_RANDOM_ACCESS_ITERATORS 0 #endif -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS - #define PLF_HIVE_RELATIONAL_OPERATORS 1 // random access iterators require relational operators +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS + #define SG14_HIVE_RELATIONAL_OPERATORS 1 // random access iterators require relational operators #endif -#ifndef PLF_HIVE_RELATIONAL_OPERATORS - #define PLF_HIVE_RELATIONAL_OPERATORS 1 +#ifndef SG14_HIVE_RELATIONAL_OPERATORS + #define SG14_HIVE_RELATIONAL_OPERATORS 1 #endif -#ifndef PLF_HIVE_DEBUGGING - #define PLF_HIVE_DEBUGGING 0 +#ifndef SG14_HIVE_DEBUGGING + #define SG14_HIVE_DEBUGGING 0 #endif #include @@ -67,7 +66,7 @@ #include #include -namespace plf { +namespace sg14 { // Polyfill std::type_identity_t template struct hive_identity { using type = T; }; @@ -103,7 +102,7 @@ static inline void hive_try_finally(F&& task, R&& finally) { task(); } -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 struct hive_limits { constexpr hive_limits(size_t mn, size_t mx) noexcept : min(mn), max(mx) {} size_t min, max; @@ -119,7 +118,7 @@ namespace hive_priority { }; } -template , class priority = plf::hive_priority::performance> +template , class priority = sg14::hive_priority::performance> class hive { template class hive_iterator; template class hive_reverse_iterator; @@ -217,12 +216,12 @@ class hive { // as an indication to remove the group. Also used in combination with capacity to check if group is full. GroupPtr next_erasure_ = nullptr; // The next group in the singly-linked list of groups with erasures ie. with active erased-element free lists. nullptr if no next group. -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS size_type groupno_ = 0; // Used for comparison (> < >= <= <=>) iterator operators (used by distance function and user). #endif -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS inline size_t group_number() const { return groupno_; } inline void set_group_number(size_type x) { groupno_ = x; } #else @@ -230,7 +229,7 @@ class hive { inline void set_group_number(size_type) { } #endif -#if PLF_HIVE_DEBUGGING +#if SG14_HIVE_DEBUGGING void debug_dump() { printf( " group #%zu [%zu/%zu used] (last_endpoint=%p, elts=%p, skipfield=%p, freelist=%zu, erasenext=%p)", @@ -261,7 +260,7 @@ class hive { printf(" [%d]\n", int(skipfield(capacity))); } } -#endif // PLF_HIVE_DEBUGGING +#endif // SG14_HIVE_DEBUGGING explicit group(skipfield_type cap) : last_endpoint(addr_of_element(0)), capacity(cap) @@ -300,16 +299,16 @@ class hive { skipfield_type idx_ = 0; public: -#if PLF_HIVE_DEBUGGING +#if SG14_HIVE_DEBUGGING void debug_dump() const { printf("iterator("); if (group_) printf("#%zu", group_->group_number()); else printf("null"); printf(", %zu)\n", size_t(idx_)); } -#endif // PLF_HIVE_DEBUGGING +#endif // SG14_HIVE_DEBUGGING -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS using iterator_category = std::random_access_iterator_tag; #else using iterator_category = std::bidirectional_iterator_tag; @@ -354,7 +353,7 @@ class hive { friend bool operator!=(const hive_iterator& a, const hive_iterator& b) { return a.group_ != b.group_ || a.idx_ != b.idx_; } #endif -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_impl_three_way_comparison >= 201907 friend std::strong_ordering operator<=>(const hive_iterator& a, const hive_iterator& b) { return a.group_ == b.group_ ? @@ -617,7 +616,7 @@ class hive { } difference_type distance(hive_iterator last) const { -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS if (last < *this) { return -last.distance_forward(*this); } @@ -625,7 +624,7 @@ class hive { return distance_forward(last); } -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS friend hive_iterator& operator+=(hive_iterator& a, difference_type n) { a.advance(n); return a; } friend hive_iterator& operator-=(hive_iterator& a, difference_type n) { a.advance(-n); return a; } friend hive_iterator operator+(const hive_iterator& a, difference_type n) { return a.next(n); } @@ -641,7 +640,7 @@ class hive { hive_iterator it_; public: -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS using iterator_category = std::random_access_iterator_tag; #else using iterator_category = std::bidirectional_iterator_tag; @@ -672,7 +671,7 @@ class hive { friend bool operator!=(const hive_reverse_iterator& a, const hive_reverse_iterator& b) { return b.it_ != a.it_; } #endif -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_impl_three_way_comparison >= 201907 friend std::strong_ordering operator<=>(const hive_reverse_iterator& a, const hive_reverse_iterator& b) { return (b.it_ <=> a.it_); } #else @@ -712,7 +711,7 @@ class hive { it_.advance(-n); } -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS friend hive_reverse_iterator& operator+=(hive_reverse_iterator& a, difference_type n) { a.advance(n); return a; } friend hive_reverse_iterator& operator-=(hive_reverse_iterator& a, difference_type n) { a.advance(-n); return a; } friend hive_reverse_iterator operator+(const hive_reverse_iterator& a, difference_type n) { return a.next(n); } @@ -725,9 +724,9 @@ class hive { public: void assert_invariants() const { -#if PLF_HIVE_DEBUGGING +#if SG14_HIVE_DEBUGGING assert(size_ <= capacity_); -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 assert(min_group_capacity_ <= max_group_capacity_); #endif if (size_ == 0) { @@ -760,7 +759,7 @@ class hive { size_type total_size = 0; size_type total_cap = 0; for (GroupPtr g = begin_.group_; g != nullptr; g = g->next_group) { -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 assert(min_group_capacity_ <= g->capacity); assert(g->capacity <= max_group_capacity_); #endif @@ -783,7 +782,7 @@ class hive { if (g->size != g->capacity && g->next_group != nullptr) { assert(!g->is_packed()); } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS if (g->next_group != nullptr) { assert(g->group_number() < g->next_group->group_number()); } @@ -810,7 +809,7 @@ class hive { assert(total_size == size_); assert((unused_groups_ != nullptr) == (unused_groups_tail_ != nullptr)); for (GroupPtr g = unused_groups_; g != nullptr; g = g->next_group) { -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 assert(min_group_capacity_ <= g->capacity); assert(g->capacity <= max_group_capacity_); #endif @@ -834,12 +833,12 @@ class hive { } void debug_dump() const { -#if PLF_HIVE_DEBUGGING +#if SG14_HIVE_DEBUGGING printf( "hive [%zu/%zu used] (erase=%p, unused=%p, mincap=%zu, maxcap=%zu)\n", size_t(size_), size_t(capacity_), groups_with_erasures_, unused_groups_, -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 size_t(impl_min_block_size()), size_t(impl_max_block_size()) #else size_t(min_group_capacity_), size_t(max_group_capacity_) @@ -870,7 +869,7 @@ class hive { printf(" %zu", g->group_number()); } printf("\n"); -#endif // PLF_HIVE_DEBUGGING +#endif // SG14_HIVE_DEBUGGING } private: @@ -882,13 +881,13 @@ class hive { size_type size_ = 0; size_type capacity_ = 0; allocator_type allocator_; -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 skipfield_type min_group_capacity_ = block_capacity_hard_limits().min; skipfield_type max_group_capacity_ = block_capacity_hard_limits().max; #endif -#if !PLF_HIVE_P2596 - static inline void check_limits(plf::hive_limits soft) { +#if !SG14_HIVE_P2596 + static inline void check_limits(sg14::hive_limits soft) { auto hard = block_capacity_hard_limits(); if (!(hard.min <= soft.min && soft.min <= soft.max && soft.max <= hard.max)) { throw std::length_error("Supplied limits are outside the allowable range"); @@ -914,7 +913,7 @@ class hive { capacity_ = 0; } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS void renumber_all_groups() { size_type groupno = 0; for (GroupPtr g = begin_.group_; g != nullptr; g = g->next_group) { @@ -930,7 +929,7 @@ class hive { explicit hive(const allocator_type &alloc) : allocator_(alloc) {} hive(const hive& h) : hive(h, std::allocator_traits::select_on_container_copy_construction(h.allocator_)) {} -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 hive(const hive& h, const hive_identity_t& alloc) : allocator_(alloc) { @@ -938,14 +937,14 @@ class hive { range_assign_impl(h.begin(), h.end()); } #else - explicit hive(plf::hive_limits limits) : + explicit hive(sg14::hive_limits limits) : min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) { check_limits(limits); } - hive(plf::hive_limits limits, const allocator_type &alloc) : + hive(sg14::hive_limits limits, const allocator_type &alloc) : allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -972,7 +971,7 @@ class hive { size_(source.size_), capacity_(source.capacity_), allocator_(source.get_allocator()) -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 , min_group_capacity_(source.min_group_capacity_) , max_group_capacity_(source.max_group_capacity_) #endif @@ -991,7 +990,7 @@ class hive { if (should_use_source_allocator) { *this = std::move(source); } else { -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 reshape(source.block_capacity_limits()); #endif reserve(source.size()); @@ -1032,8 +1031,8 @@ class hive { assign(il.begin(), il.end()); } -#if !PLF_HIVE_P2596 - hive(size_type n, const T& value, plf::hive_limits limits, const allocator_type &alloc = allocator_type()) : +#if !SG14_HIVE_P2596 + hive(size_type n, const T& value, sg14::hive_limits limits, const allocator_type &alloc = allocator_type()) : allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -1042,7 +1041,7 @@ class hive { assign(n, value); } - hive(size_type n, plf::hive_limits limits, const allocator_type &alloc = allocator_type()) : + hive(size_type n, sg14::hive_limits limits, const allocator_type &alloc = allocator_type()) : allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -1052,7 +1051,7 @@ class hive { } template::value>> - hive(It first, It last, plf::hive_limits limits, const allocator_type &alloc = allocator_type()) : + hive(It first, It last, sg14::hive_limits limits, const allocator_type &alloc = allocator_type()) : allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -1061,7 +1060,7 @@ class hive { assign(std::move(first), std::move(last)); } - hive(std::initializer_list il, plf::hive_limits limits, const allocator_type &alloc = allocator_type()): + hive(std::initializer_list il, sg14::hive_limits limits, const allocator_type &alloc = allocator_type()): allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -1087,10 +1086,10 @@ class hive { assign_range(std::forward(rg)); } -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 template requires std::convertible_to, T> - explicit hive(std::from_range_t, R&& rg, plf::hive_limits limits, const allocator_type &alloc = allocator_type()) : + explicit hive(std::from_range_t, R&& rg, sg14::hive_limits limits, const allocator_type &alloc = allocator_type()) : allocator_(alloc), min_group_capacity_(static_cast(limits.min)), max_group_capacity_(static_cast(limits.max)) @@ -1098,7 +1097,7 @@ class hive { check_limits(limits); assign_range(std::forward(rg)); } -#endif // !PLF_HIVE_P2596 +#endif // !SG14_HIVE_P2596 #endif // __cpp_lib_ranges >= 201911 && __cpp_lib_ranges_to_container >= 202202 ~hive() { @@ -1682,7 +1681,7 @@ class hive { swap(unused_groups_tail_, source.unused_groups_tail_); swap(size_, source.size_); swap(capacity_, source.capacity_); -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 swap(min_group_capacity_, source.min_group_capacity_); swap(max_group_capacity_, source.max_group_capacity_); #endif @@ -1724,7 +1723,7 @@ class hive { throw std::length_error("Result of splice would exceed max_size()"); } -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 if (source.min_group_capacity_ < min_group_capacity_ || source.max_group_capacity_ > max_group_capacity_) { for (GroupPtr it = source.begin_.group_; it != nullptr; it = it->next_group) { if (it->capacity < min_group_capacity_ || it->capacity > max_group_capacity_) { @@ -1765,7 +1764,7 @@ class hive { source.begin_.group_->prev_group = end_.group_; if (end_.group_ != nullptr) { end_.group_->next_group = source.begin_.group_; -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS if (source.begin_.group_->group_number() <= end_.group_->group_number()) { renumber_all_groups(); } @@ -1993,7 +1992,7 @@ class hive { } inline void update_subsequent_group_numbers(GroupPtr g) { -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS do { g->groupno_ -= 1; g = g->next_group; @@ -2085,7 +2084,7 @@ class hive { inline size_type max_size() const noexcept { return std::allocator_traits::max_size(get_allocator()); } inline size_type capacity() const noexcept { return capacity_; } -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 inline size_type max_block_size() const noexcept { size_type a = impl_max_block_size(); size_type b = max_size(); @@ -2100,7 +2099,7 @@ class hive { inline size_type recommend_block_size() const { size_type r = size_; if (r < 8) r = 8; -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 if (r > impl_max_block_size()) r = impl_max_block_size(); #else if (r < min_group_capacity_) r = min_group_capacity_; @@ -2190,7 +2189,7 @@ class hive { } public: -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 bool reshape(size_type min, size_type n = 0) { if (n > max_size()) { throw std::length_error("n must be at most max_size()"); @@ -2227,7 +2226,7 @@ class hive { } } #else - void reshape(plf::hive_limits limits) { + void reshape(sg14::hive_limits limits) { check_limits(limits); assert_invariants(); @@ -2245,12 +2244,12 @@ class hive { max_group_capacity_ = limits.max; } - inline plf::hive_limits block_capacity_limits() const noexcept { - return plf::hive_limits(min_group_capacity_, max_group_capacity_); + inline sg14::hive_limits block_capacity_limits() const noexcept { + return sg14::hive_limits(min_group_capacity_, max_group_capacity_); } - static constexpr plf::hive_limits block_capacity_hard_limits() noexcept { - return plf::hive_limits(impl_min_block_size(), std::numeric_limits::max()); + static constexpr sg14::hive_limits block_capacity_hard_limits() noexcept { + return sg14::hive_limits(impl_min_block_size(), std::numeric_limits::max()); } #endif @@ -2297,7 +2296,7 @@ class hive { unused_groups_tail_ = std::move(source.unused_groups_tail_); size_ = source.size_; capacity_ = source.capacity_; -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 min_group_capacity_ = source.min_group_capacity_; max_group_capacity_ = source.max_group_capacity_; #endif @@ -2323,7 +2322,7 @@ class hive { } void shrink_to_fit() { -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 const size_type min = impl_min_block_size(); const size_type max = impl_max_block_size(); #else @@ -2374,7 +2373,7 @@ class hive { } void reserve(size_type n) { -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 reserve_impl(n, impl_min_block_size(), impl_max_block_size()); #else reserve_impl(n, min_group_capacity_, max_group_capacity_); @@ -2460,15 +2459,15 @@ class hive { } inline size_type unique() { return unique(std::equal_to()); } -}; // hive +}; -} // namespace plf +} // namespace sg14 namespace std { template - typename plf::hive::size_type erase_if(plf::hive& h, Pred pred) { - typename plf::hive::size_type count = 0; + typename sg14::hive::size_type erase_if(sg14::hive& h, Pred pred) { + typename sg14::hive::size_type count = 0; auto end = h.end(); for (auto it = h.begin(); it != end; ++it) { if (pred(*it)) { @@ -2492,9 +2491,7 @@ namespace std { } template - inline typename plf::hive::size_type erase(plf::hive& h, const T& value) { + inline typename sg14::hive::size_type erase(sg14::hive& h, const T& value) { return std::erase_if(h, [&](const T &x) { return x == value; }); } } // namespace std - -#endif // PLF_HIVE_H diff --git a/include/sg14/inplace_function.h b/include/sg14/inplace_function.h index 573187cb..95c7e885 100644 --- a/include/sg14/inplace_function.h +++ b/include/sg14/inplace_function.h @@ -34,7 +34,7 @@ #define SG14_INPLACE_FUNCTION_THROW(x) throw (x) #endif -namespace stdext { +namespace sg14 { namespace inplace_function_detail { @@ -379,4 +379,4 @@ class inplace_function } }; -} // namespace stdext +} // namespace sg14 diff --git a/include/sg14/ring.h b/include/sg14/ring.h deleted file mode 100644 index 0820918c..00000000 --- a/include/sg14/ring.h +++ /dev/null @@ -1,539 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace sg14 -{ - template - struct null_popper - { - void operator()(T&) const noexcept; - }; - - template - struct default_popper - { - T operator()(T& t) const; - }; - - template - struct copy_popper - { - copy_popper(T t); - T operator()(T& t) const; - private: - T m_copy; - }; - - template - class ring_iterator; - - template> - class ring_span - { - public: - using type = ring_span; - using size_type = std::size_t; - using value_type = T; - using pointer = T*; - using reference = T&; - using const_reference = const T&; - using iterator = ring_iterator; - using const_iterator = ring_iterator; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - - friend class ring_iterator; - friend class ring_iterator; - - template - ring_span(ContiguousIterator begin, ContiguousIterator end, Popper p = Popper()) noexcept; - - template - ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first, size_type size, Popper p = Popper()) noexcept; - - ring_span(ring_span&&) = default; - ring_span& operator=(ring_span&&) = default; - - bool empty() const noexcept; - bool full() const noexcept; - size_type size() const noexcept; - size_type capacity() const noexcept; - - reference front() noexcept; - const_reference front() const noexcept; - reference back() noexcept; - const_reference back() const noexcept; - - iterator begin() noexcept; - const_iterator begin() const noexcept; - iterator end() noexcept; - const_iterator end() const noexcept; - - const_iterator cbegin() const noexcept; - const_reverse_iterator crbegin() const noexcept; - reverse_iterator rbegin() noexcept; - const_reverse_iterator rbegin() const noexcept; - const_iterator cend() const noexcept; - const_reverse_iterator crend() const noexcept; - reverse_iterator rend() noexcept; - const_reverse_iterator rend() const noexcept; - - template::value>> - void push_back(const value_type& from_value) noexcept(std::is_nothrow_copy_assignable::value); - template::value>> - void push_back(value_type&& from_value) noexcept(std::is_nothrow_move_assignable::value); - template - void emplace_back(FromType&&... from_value) noexcept(std::is_nothrow_constructible::value && std::is_nothrow_move_assignable::value); - auto pop_front(); - - void swap(type& rhs) noexcept;// (std::is_nothrow_swappable::value); - - // Example implementation - private: - reference at(size_type idx) noexcept; - const_reference at(size_type idx) const noexcept; - size_type back_idx() const noexcept; - void increase_size() noexcept; - - T* m_data; - size_type m_size; - size_type m_capacity; - size_type m_front_idx; - Popper m_popper; - }; - - template - void swap(ring_span&, ring_span&) noexcept; - - template - class ring_iterator - { - public: - using type = ring_iterator; - using value_type = typename Ring::value_type; - using difference_type = std::ptrdiff_t; - using pointer = typename std::conditional_t*; - using reference = typename std::conditional_t&; - using iterator_category = std::random_access_iterator_tag; - - operator ring_iterator() const noexcept; - - template - bool operator==(const ring_iterator& rhs) const noexcept; - template - bool operator!=(const ring_iterator& rhs) const noexcept; - template - bool operator<(const ring_iterator& rhs) const noexcept; - template - bool operator<=(const ring_iterator& rhs) const noexcept; - template - bool operator>(const ring_iterator& rhs) const noexcept; - template - bool operator>=(const ring_iterator& rhs) const noexcept; - - reference operator*() const noexcept; - type& operator++() noexcept; - type operator++(int) noexcept; - type& operator--() noexcept; - type operator--(int) noexcept; - - type& operator+=(std::ptrdiff_t i) noexcept; - type& operator-=(std::ptrdiff_t i) noexcept; - - template - std::ptrdiff_t operator-(const ring_iterator& rhs) const noexcept; - - // Example implementation - private: - friend Ring; - friend class ring_iterator; - using size_type = typename Ring::size_type; - ring_iterator(size_type idx, std::conditional_t* rv) noexcept; - size_type m_idx; - std::conditional_t* m_rv; - }; - - template - ring_iterator operator+(ring_iterator it, std::ptrdiff_t) noexcept; - - template - ring_iterator operator-(ring_iterator it, std::ptrdiff_t) noexcept; -} // namespace sg14 - -// Sample implementation - -template -void sg14::null_popper::operator()(T&) const noexcept -{} - -template -T sg14::default_popper::operator()(T& t) const -{ - return std::move(t); -} - -template -sg14::copy_popper::copy_popper(T t) - : m_copy(std::move(t)) -{} - -template -T sg14::copy_popper::operator()(T& t) const -{ - T old = m_copy; - using std::swap; - swap(old, t); - return old; -} - -template -template -sg14::ring_span::ring_span(ContiguousIterator begin, ContiguousIterator end, Popper p) noexcept - : m_data(&*begin) - , m_size(0) - , m_capacity(end - begin) - , m_front_idx(0) - , m_popper(std::move(p)) -{} - -template -template -sg14::ring_span::ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first, size_type size, Popper p) noexcept - : m_data(&*begin) - , m_size(size) - , m_capacity(end - begin) - , m_front_idx(first - begin) - , m_popper(std::move(p)) -{} - -template -bool sg14::ring_span::empty() const noexcept -{ - return m_size == 0; -} - -template -bool sg14::ring_span::full() const noexcept -{ - return m_size == m_capacity; -} - -template -typename sg14::ring_span::size_type sg14::ring_span::size() const noexcept -{ - return m_size; -} - -template -typename sg14::ring_span::size_type sg14::ring_span::capacity() const noexcept -{ - return m_capacity; -} - -template -typename sg14::ring_span::reference sg14::ring_span::front() noexcept -{ - return *begin(); -} - -template -typename sg14::ring_span::reference sg14::ring_span::back() noexcept -{ - return *(--end()); -} - -template -typename sg14::ring_span::const_reference sg14::ring_span::front() const noexcept -{ - return *begin(); -} - -template -typename sg14::ring_span::const_reference sg14::ring_span::back() const noexcept -{ - return *(--end()); -} - -template -typename sg14::ring_span::iterator sg14::ring_span::begin() noexcept -{ - return iterator(m_front_idx, this); -} - -template -typename sg14::ring_span::const_iterator sg14::ring_span::begin() const noexcept -{ - return const_iterator(m_front_idx, this); -} - -template -typename sg14::ring_span::iterator sg14::ring_span::end() noexcept -{ - return iterator(size() + m_front_idx, this); -} - -template -typename sg14::ring_span::const_iterator sg14::ring_span::end() const noexcept -{ - return const_iterator(size() + m_front_idx, this); -} - -template -typename sg14::ring_span::const_iterator sg14::ring_span::cbegin() const noexcept -{ - return begin(); -} - -template -typename sg14::ring_span::reverse_iterator sg14::ring_span::rbegin() noexcept -{ - return reverse_iterator(end()); -} - -template -typename sg14::ring_span::const_reverse_iterator sg14::ring_span::rbegin() const noexcept -{ - return const_reverse_iterator(end()); -} - -template -typename sg14::ring_span::const_reverse_iterator sg14::ring_span::crbegin() const noexcept -{ - return const_reverse_iterator(end()); -} - -template -typename sg14::ring_span::const_iterator sg14::ring_span::cend() const noexcept -{ - return end(); -} - -template -typename sg14::ring_span::reverse_iterator sg14::ring_span::rend() noexcept -{ - return reverse_iterator(begin()); -} - -template -typename sg14::ring_span::const_reverse_iterator sg14::ring_span::rend() const noexcept -{ - return const_reverse_iterator(begin()); -} - -template -typename sg14::ring_span::const_reverse_iterator sg14::ring_span::crend() const noexcept -{ - return const_reverse_iterator(begin()); -} - -template -template -void sg14::ring_span::push_back(const T& value) noexcept(std::is_nothrow_copy_assignable::value) -{ - m_data[back_idx()] = value; - increase_size(); -} - -template -template -void sg14::ring_span::push_back(T&& value) noexcept(std::is_nothrow_move_assignable::value) -{ - m_data[back_idx()] = std::move(value); - increase_size(); -} - -template -template -void sg14::ring_span::emplace_back(FromType&&... from_value) noexcept(std::is_nothrow_constructible::value && std::is_nothrow_move_assignable::value) -{ - m_data[back_idx()] = T(std::forward(from_value)...); - increase_size(); -} - -template -auto sg14::ring_span::pop_front() -{ - assert(m_size != 0); - auto old_front_idx = m_front_idx; - m_front_idx = (m_front_idx + 1) % m_capacity; - --m_size; - return m_popper(m_data[old_front_idx]); -} - -template -void sg14::ring_span::swap(sg14::ring_span& rhs) noexcept//(std::is_nothrow_swappable::value) -{ - using std::swap; - swap(m_data, rhs.m_data); - swap(m_size, rhs.m_size); - swap(m_capacity, rhs.m_capacity); - swap(m_front_idx, rhs.m_front_idx); - swap(m_popper, rhs.m_popper); -} - -template -typename sg14::ring_span::reference sg14::ring_span::at(size_type i) noexcept -{ - return m_data[i % m_capacity]; -} - -template -typename sg14::ring_span::const_reference sg14::ring_span::at(size_type i) const noexcept -{ - return m_data[i % m_capacity]; -} - -template -typename sg14::ring_span::size_type sg14::ring_span::back_idx() const noexcept -{ - return (m_front_idx + m_size) % m_capacity; -} - -template -void sg14::ring_span::increase_size() noexcept -{ - if (++m_size > m_capacity) - { - m_size = m_capacity; - m_front_idx = (m_front_idx + 1) % m_capacity; - } -} - -template -sg14::ring_iterator::operator sg14::ring_iterator() const noexcept -{ - return sg14::ring_iterator(m_idx, m_rv); -} - -template -template -bool sg14::ring_iterator::operator==(const sg14::ring_iterator& rhs) const noexcept -{ - return (m_idx == rhs.m_idx) && (m_rv == rhs.m_rv); -} - -template -template -bool sg14::ring_iterator::operator!=(const sg14::ring_iterator& rhs) const noexcept -{ - return !(*this == rhs); -} - -template -template -bool sg14::ring_iterator::operator<(const sg14::ring_iterator& rhs) const noexcept -{ - return (m_idx < rhs.m_idx) && (m_rv == rhs.m_rv); -} - -template -template -bool sg14::ring_iterator::operator<=(const sg14::ring_iterator& rhs) const noexcept -{ - return !(rhs < *this); -} - -template -template -bool sg14::ring_iterator::operator>(const sg14::ring_iterator& rhs) const noexcept -{ - return (rhs < *this); -} - -template -template -bool sg14::ring_iterator::operator>=(const sg14::ring_iterator& rhs) const noexcept -{ - return !(*this < rhs); -} - -template -typename sg14::ring_iterator::reference sg14::ring_iterator::operator*() const noexcept -{ - return m_rv->at(m_idx); -} - -template -sg14::ring_iterator& sg14::ring_iterator::operator++() noexcept -{ - ++m_idx; - return *this; -} - -template -sg14::ring_iterator sg14::ring_iterator::operator++(int) noexcept -{ - auto r(*this); - ++*this; - return r; -} - -template -sg14::ring_iterator& sg14::ring_iterator::operator--() noexcept -{ - --m_idx; - return *this; -} - -template -sg14::ring_iterator sg14::ring_iterator::operator--(int) noexcept -{ - auto r(*this); - --*this; - return r; -} - -template -sg14::ring_iterator& sg14::ring_iterator::operator+=(std::ptrdiff_t i) noexcept -{ - this->m_idx += i; - return *this; -} - -template -sg14::ring_iterator& sg14::ring_iterator::operator-=(std::ptrdiff_t i) noexcept -{ - this->m_idx -= i; - return *this; -} - -template -template -std::ptrdiff_t sg14::ring_iterator::operator-(const sg14::ring_iterator& rhs) const noexcept -{ - return static_cast(this->m_idx) - static_cast(rhs.m_idx); -} - -template -sg14::ring_iterator::ring_iterator(typename sg14::ring_iterator::size_type idx, std::conditional_t* rv) noexcept - : m_idx(idx) - , m_rv(rv) -{} - - -namespace sg14 -{ - template - void swap(ring_span& a, ring_span& b) noexcept - { - a.swap(b); - } - - template - ring_iterator operator+(ring_iterator it, std::ptrdiff_t i) noexcept - { - it += i; - return it; - } - - template - ring_iterator operator-(ring_iterator it, std::ptrdiff_t i) noexcept - { - it -= i; - return it; - } -} // namespace sg14 diff --git a/include/sg14/ring_span.h b/include/sg14/ring_span.h new file mode 100644 index 00000000..1f1891ef --- /dev/null +++ b/include/sg14/ring_span.h @@ -0,0 +1,520 @@ +#pragma once + +#include +#include +#include +#include + +namespace sg14 +{ + template + struct null_popper { + void operator()(T&) const noexcept; + }; + + template + struct default_popper { + T operator()(T& t) const; + }; + + template + struct copy_popper { + copy_popper(T t); + T operator()(T& t) const; + private: + T m_copy; + }; + + template + class ring_iterator; + + template> + class ring_span { + public: + using type = ring_span; + using size_type = std::size_t; + using value_type = T; + using pointer = T*; + using reference = T&; + using const_reference = const T&; + using iterator = ring_iterator; + using const_iterator = ring_iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + + friend class ring_iterator; + friend class ring_iterator; + + template + ring_span(ContiguousIterator begin, ContiguousIterator end, Popper p = Popper()) noexcept; + + template + ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first, size_type size, Popper p = Popper()) noexcept; + + ring_span(ring_span&&) = default; + ring_span& operator=(ring_span&&) = default; + + bool empty() const noexcept; + bool full() const noexcept; + size_type size() const noexcept; + size_type capacity() const noexcept; + + reference front() noexcept; + const_reference front() const noexcept; + reference back() noexcept; + const_reference back() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + const_iterator cbegin() const noexcept; + const_reverse_iterator crbegin() const noexcept; + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crend() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + template::value>> + void push_back(const value_type& from_value) noexcept(std::is_nothrow_copy_assignable::value); + template::value>> + void push_back(value_type&& from_value) noexcept(std::is_nothrow_move_assignable::value); + template + void emplace_back(FromType&&... from_value) noexcept(std::is_nothrow_constructible::value && std::is_nothrow_move_assignable::value); + auto pop_front(); + + void swap(type& rhs) noexcept;// (std::is_nothrow_swappable::value); + + // Example implementation + private: + reference at(size_type idx) noexcept; + const_reference at(size_type idx) const noexcept; + size_type back_idx() const noexcept; + void increase_size() noexcept; + + T* m_data; + size_type m_size; + size_type m_capacity; + size_type m_front_idx; + Popper m_popper; + }; + + template + void swap(ring_span&, ring_span&) noexcept; + + template + class ring_iterator { + public: + using type = ring_iterator; + using value_type = typename Ring::value_type; + using difference_type = std::ptrdiff_t; + using pointer = typename std::conditional_t*; + using reference = typename std::conditional_t&; + using iterator_category = std::random_access_iterator_tag; + + operator ring_iterator() const noexcept; + + template + bool operator==(const ring_iterator& rhs) const noexcept; + template + bool operator!=(const ring_iterator& rhs) const noexcept; + template + bool operator<(const ring_iterator& rhs) const noexcept; + template + bool operator<=(const ring_iterator& rhs) const noexcept; + template + bool operator>(const ring_iterator& rhs) const noexcept; + template + bool operator>=(const ring_iterator& rhs) const noexcept; + + reference operator*() const noexcept; + type& operator++() noexcept; + type operator++(int) noexcept; + type& operator--() noexcept; + type operator--(int) noexcept; + + type& operator+=(std::ptrdiff_t i) noexcept; + type& operator-=(std::ptrdiff_t i) noexcept; + + template + std::ptrdiff_t operator-(const ring_iterator& rhs) const noexcept; + + // Example implementation + private: + friend Ring; + friend class ring_iterator; + using size_type = typename Ring::size_type; + ring_iterator(size_type idx, std::conditional_t* rv) noexcept; + size_type m_idx; + std::conditional_t* m_rv; + }; + + template + ring_iterator operator+(ring_iterator it, std::ptrdiff_t) noexcept; + + template + ring_iterator operator-(ring_iterator it, std::ptrdiff_t) noexcept; +} // namespace sg14 + +// Sample implementation + +template +void sg14::null_popper::operator()(T&) const noexcept {} + +template +T sg14::default_popper::operator()(T& t) const { + return std::move(t); +} + +template +sg14::copy_popper::copy_popper(T t) + : m_copy(std::move(t)) {} + +template +T sg14::copy_popper::operator()(T& t) const { + T old = m_copy; + using std::swap; + swap(old, t); + return old; +} + +template +template +sg14::ring_span::ring_span(ContiguousIterator begin, ContiguousIterator end, Popper p) noexcept + : m_data(&*begin) + , m_size(0) + , m_capacity(end - begin) + , m_front_idx(0) + , m_popper(std::move(p)) +{} + +template +template +sg14::ring_span::ring_span(ContiguousIterator begin, ContiguousIterator end, ContiguousIterator first, size_type size, Popper p) noexcept + : m_data(&*begin) + , m_size(size) + , m_capacity(end - begin) + , m_front_idx(first - begin) + , m_popper(std::move(p)) +{} + +template +bool sg14::ring_span::empty() const noexcept { + return m_size == 0; +} + +template +bool sg14::ring_span::full() const noexcept { + return m_size == m_capacity; +} + +template +typename sg14::ring_span::size_type sg14::ring_span::size() const noexcept { + return m_size; +} + +template +typename sg14::ring_span::size_type sg14::ring_span::capacity() const noexcept { + return m_capacity; +} + +template +typename sg14::ring_span::reference sg14::ring_span::front() noexcept { + return *begin(); +} + +template +typename sg14::ring_span::reference sg14::ring_span::back() noexcept { + return *(--end()); +} + +template +typename sg14::ring_span::const_reference sg14::ring_span::front() const noexcept { + return *begin(); +} + +template +typename sg14::ring_span::const_reference sg14::ring_span::back() const noexcept +{ + return *(--end()); +} + +template +typename sg14::ring_span::iterator sg14::ring_span::begin() noexcept +{ + return iterator(m_front_idx, this); +} + +template +typename sg14::ring_span::const_iterator sg14::ring_span::begin() const noexcept +{ + return const_iterator(m_front_idx, this); +} + +template +typename sg14::ring_span::iterator sg14::ring_span::end() noexcept +{ + return iterator(size() + m_front_idx, this); +} + +template +typename sg14::ring_span::const_iterator sg14::ring_span::end() const noexcept +{ + return const_iterator(size() + m_front_idx, this); +} + +template +typename sg14::ring_span::const_iterator sg14::ring_span::cbegin() const noexcept +{ + return begin(); +} + +template +typename sg14::ring_span::reverse_iterator sg14::ring_span::rbegin() noexcept +{ + return reverse_iterator(end()); +} + +template +typename sg14::ring_span::const_reverse_iterator sg14::ring_span::rbegin() const noexcept +{ + return const_reverse_iterator(end()); +} + +template +typename sg14::ring_span::const_reverse_iterator sg14::ring_span::crbegin() const noexcept +{ + return const_reverse_iterator(end()); +} + +template +typename sg14::ring_span::const_iterator sg14::ring_span::cend() const noexcept +{ + return end(); +} + +template +typename sg14::ring_span::reverse_iterator sg14::ring_span::rend() noexcept +{ + return reverse_iterator(begin()); +} + +template +typename sg14::ring_span::const_reverse_iterator sg14::ring_span::rend() const noexcept +{ + return const_reverse_iterator(begin()); +} + +template +typename sg14::ring_span::const_reverse_iterator sg14::ring_span::crend() const noexcept +{ + return const_reverse_iterator(begin()); +} + +template +template +void sg14::ring_span::push_back(const T& value) noexcept(std::is_nothrow_copy_assignable::value) +{ + m_data[back_idx()] = value; + increase_size(); +} + +template +template +void sg14::ring_span::push_back(T&& value) noexcept(std::is_nothrow_move_assignable::value) +{ + m_data[back_idx()] = std::move(value); + increase_size(); +} + +template +template +void sg14::ring_span::emplace_back(FromType&&... from_value) noexcept(std::is_nothrow_constructible::value && std::is_nothrow_move_assignable::value) +{ + m_data[back_idx()] = T(std::forward(from_value)...); + increase_size(); +} + +template +auto sg14::ring_span::pop_front() +{ + assert(m_size != 0); + auto old_front_idx = m_front_idx; + m_front_idx = (m_front_idx + 1) % m_capacity; + --m_size; + return m_popper(m_data[old_front_idx]); +} + +template +void sg14::ring_span::swap(sg14::ring_span& rhs) noexcept//(std::is_nothrow_swappable::value) +{ + using std::swap; + swap(m_data, rhs.m_data); + swap(m_size, rhs.m_size); + swap(m_capacity, rhs.m_capacity); + swap(m_front_idx, rhs.m_front_idx); + swap(m_popper, rhs.m_popper); +} + +template +typename sg14::ring_span::reference sg14::ring_span::at(size_type i) noexcept +{ + return m_data[i % m_capacity]; +} + +template +typename sg14::ring_span::const_reference sg14::ring_span::at(size_type i) const noexcept +{ + return m_data[i % m_capacity]; +} + +template +typename sg14::ring_span::size_type sg14::ring_span::back_idx() const noexcept +{ + return (m_front_idx + m_size) % m_capacity; +} + +template +void sg14::ring_span::increase_size() noexcept +{ + if (++m_size > m_capacity) + { + m_size = m_capacity; + m_front_idx = (m_front_idx + 1) % m_capacity; + } +} + +template +sg14::ring_iterator::operator sg14::ring_iterator() const noexcept +{ + return sg14::ring_iterator(m_idx, m_rv); +} + +template +template +bool sg14::ring_iterator::operator==(const sg14::ring_iterator& rhs) const noexcept +{ + return (m_idx == rhs.m_idx) && (m_rv == rhs.m_rv); +} + +template +template +bool sg14::ring_iterator::operator!=(const sg14::ring_iterator& rhs) const noexcept +{ + return !(*this == rhs); +} + +template +template +bool sg14::ring_iterator::operator<(const sg14::ring_iterator& rhs) const noexcept +{ + return (m_idx < rhs.m_idx) && (m_rv == rhs.m_rv); +} + +template +template +bool sg14::ring_iterator::operator<=(const sg14::ring_iterator& rhs) const noexcept +{ + return !(rhs < *this); +} + +template +template +bool sg14::ring_iterator::operator>(const sg14::ring_iterator& rhs) const noexcept +{ + return (rhs < *this); +} + +template +template +bool sg14::ring_iterator::operator>=(const sg14::ring_iterator& rhs) const noexcept +{ + return !(*this < rhs); +} + +template +typename sg14::ring_iterator::reference sg14::ring_iterator::operator*() const noexcept +{ + return m_rv->at(m_idx); +} + +template +sg14::ring_iterator& sg14::ring_iterator::operator++() noexcept +{ + ++m_idx; + return *this; +} + +template +sg14::ring_iterator sg14::ring_iterator::operator++(int) noexcept +{ + auto r(*this); + ++*this; + return r; +} + +template +sg14::ring_iterator& sg14::ring_iterator::operator--() noexcept +{ + --m_idx; + return *this; +} + +template +sg14::ring_iterator sg14::ring_iterator::operator--(int) noexcept +{ + auto r(*this); + --*this; + return r; +} + +template +sg14::ring_iterator& sg14::ring_iterator::operator+=(std::ptrdiff_t i) noexcept +{ + this->m_idx += i; + return *this; +} + +template +sg14::ring_iterator& sg14::ring_iterator::operator-=(std::ptrdiff_t i) noexcept +{ + this->m_idx -= i; + return *this; +} + +template +template +std::ptrdiff_t sg14::ring_iterator::operator-(const sg14::ring_iterator& rhs) const noexcept +{ + return static_cast(this->m_idx) - static_cast(rhs.m_idx); +} + +template +sg14::ring_iterator::ring_iterator(typename sg14::ring_iterator::size_type idx, std::conditional_t* rv) noexcept + : m_idx(idx) + , m_rv(rv) +{} + + +namespace sg14 +{ + template + void swap(ring_span& a, ring_span& b) noexcept { + a.swap(b); + } + + template + ring_iterator operator+(ring_iterator it, std::ptrdiff_t i) noexcept { + it += i; + return it; + } + + template + ring_iterator operator-(ring_iterator it, std::ptrdiff_t i) noexcept { + it -= i; + return it; + } +} // namespace sg14 diff --git a/include/sg14/slot_map.h b/include/sg14/slot_map.h index 2b574f48..dc043dce 100644 --- a/include/sg14/slot_map.h +++ b/include/sg14/slot_map.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -35,7 +36,7 @@ #define SLOT_MAP_THROW_EXCEPTION(type, ...) throw type(__VA_ARGS__) #endif -namespace stdext { +namespace sg14 { namespace slot_map_detail { @@ -109,6 +110,15 @@ class slot_map constexpr slot_map& operator=(slot_map&&) = default; ~slot_map() = default; + constexpr slot_map(std::initializer_list il) : slot_map(il.begin(), il.end()) {} + + template::value>> + constexpr slot_map(It first, It last) { + for ( ; first != last; ++first) { + insert(*first); + } + } + // The at() functions have both generation counter checking // and bounds checking, and throw if either check fails. // O(1) time and space complexity. @@ -376,4 +386,4 @@ constexpr void swap(slot_map& lhs, slot_map struct flat_mapt : testing::Test {}; using flat_mapt_types = testing::Types< - stdext::flat_map // basic - , stdext::flat_map> // custom comparator + sg14::flat_map // basic + , sg14::flat_map> // custom comparator #if __cplusplus >= 201402L - , stdext::flat_map> // transparent comparator + , sg14::flat_map> // transparent comparator #endif - , stdext::flat_map, std::deque> // custom container + , sg14::flat_map, std::deque> // custom container #if __cpp_lib_memory_resource >= 201603 - , stdext::flat_map, std::pmr::vector> // pmr container - , stdext::flat_map, std::pmr::vector> // uses-allocator construction + , sg14::flat_map, std::pmr::vector> // pmr container + , sg14::flat_map, std::pmr::vector> // uses-allocator construction #endif >; TYPED_TEST_SUITE(flat_mapt, flat_mapt_types); @@ -48,7 +48,7 @@ struct AmbiguousEraseWidget { TEST(flat_map, AmbiguousErase) { - stdext::flat_map fs; + sg14::flat_map fs; fs.emplace("a", 1); fs.emplace("b", 2); fs.emplace("c", 3); @@ -68,7 +68,7 @@ TEST(flat_map, ExtractDoesntSwap) { std::pmr::monotonic_buffer_resource mr; std::pmr::polymorphic_allocator a(&mr); - stdext::flat_map, std::pmr::vector, std::pmr::vector> fs({{1, 10}, {2, 20}}, a); + sg14::flat_map, std::pmr::vector, std::pmr::vector> fs({{1, 10}, {2, 20}}, a); auto ctrs = std::move(fs).extract(); assert(ctrs.keys.get_allocator() == a); assert(ctrs.values.get_allocator() == a); @@ -78,7 +78,7 @@ TEST(flat_map, ExtractDoesntSwap) // Sanity-check with std::allocator, even though this can't fail. { std::allocator a; - stdext::flat_map, std::vector, std::vector> fs({{1, 10}, {2, 20}}, a); + sg14::flat_map, std::vector, std::vector> fs({{1, 10}, {2, 20}}, a); auto ctrs = std::move(fs).extract(); assert(ctrs.keys.get_allocator() == a); assert(ctrs.values.get_allocator() == a); @@ -116,7 +116,7 @@ int InstrumentedWidget::copy_ctors = 0; TEST(flat_map, MoveOperationsPilferOwnership) { - using FS = stdext::flat_map; + using FS = sg14::flat_map; InstrumentedWidget::move_ctors = 0; InstrumentedWidget::copy_ctors = 0; FS fs; @@ -153,15 +153,15 @@ TEST(flat_map, MoveOperationsPilferOwnership) TEST(flat_map, SortedUniqueConstruction) { - auto a = stdext::sorted_unique; - stdext::sorted_unique_t b; - stdext::sorted_unique_t c{}; + auto a = sg14::sorted_unique; + sg14::sorted_unique_t b; + sg14::sorted_unique_t c{}; (void)a; (void)b; (void)c; #if 0 // TODO: GCC cannot compile this struct explicitness_tester { bool test(std::vector) { return true; } - bool test(stdext::sorted_unique_t) { return false; } + bool test(sg14::sorted_unique_t) { return false; } }; explicitness_tester tester; assert(tester.test({}) == true); @@ -170,8 +170,8 @@ TEST(flat_map, SortedUniqueConstruction) TEST(flat_map, TryEmplace) { - stdext::flat_map fm; - std::pair::iterator, bool> pair; + sg14::flat_map fm; + std::pair::iterator, bool> pair; if (true) { // try_emplace for a non-existent key does move-from. InstrumentedWidget w("abc"); @@ -228,7 +228,7 @@ TEST(flat_map, TryEmplace) TEST(flat_map, VectorBool) { - using FM = stdext::flat_map; + using FM = sg14::flat_map; FM fm; auto it_inserted = fm.emplace(true, false); assert(it_inserted.second); @@ -285,7 +285,7 @@ static auto flatmap_is_ctadable_from(long, Args&&...) TEST(flat_map, DeductionGuides) { - using stdext::flat_map; + using sg14::flat_map; #if defined(__cpp_deduction_guides) if (true) { // flat_map(Container) @@ -306,7 +306,7 @@ TEST(flat_map, DeductionGuides) flat_map fm5(il); static_assert(std::is_same_v>); assert(fm5.size() == 3); - assert(( fm5 == decltype(fm5)(stdext::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); + assert(( fm5 == decltype(fm5)(sg14::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); } if (true) { // flat_map(KeyContainer, MappedContainer) @@ -314,10 +314,10 @@ TEST(flat_map, DeductionGuides) std::vector vs {"a","b"}; flat_map fm1(vi, vs); static_assert(std::is_same_v>); - assert(( fm1 == flat_map(stdext::sorted_unique, {{1,"b"}, {2,"a"}}) )); + assert(( fm1 == flat_map(sg14::sorted_unique, {{1,"b"}, {2,"a"}}) )); flat_map fm2(std::move(vs), std::move(vi)); static_assert(std::is_same_v>); - assert(( fm2 == flat_map(stdext::sorted_unique, {{"a",2}, {"b",1}}) )); + assert(( fm2 == flat_map(sg14::sorted_unique, {{"a",2}, {"b",1}}) )); } if (true) { // flat_map(Container, Allocator) @@ -337,71 +337,71 @@ TEST(flat_map, DeductionGuides) std::vector vs {"a","b"}; flat_map fm1(vi, vs, std::allocator()); static_assert(std::is_same_v>); - assert(( fm1 == decltype(fm1)(stdext::sorted_unique, {{1,"b"}, {2,"a"}}) )); + assert(( fm1 == decltype(fm1)(sg14::sorted_unique, {{1,"b"}, {2,"a"}}) )); #if __cpp_lib_memory_resource >= 201603 std::pmr::vector pvi {2,1}; std::pmr::vector pvs {"a","b"}; flat_map fm2(pvi, pvs, std::pmr::polymorphic_allocator()); static_assert(std::is_same_v, std::pmr::vector, std::pmr::vector>>); - assert(( fm2 == decltype(fm2)(stdext::sorted_unique, {{1,"b"}, {2,"a"}}) )); + assert(( fm2 == decltype(fm2)(sg14::sorted_unique, {{1,"b"}, {2,"a"}}) )); #endif } if (true) { // flat_map(sorted_unique_t, Container) std::vector> v; - flat_map fm1(stdext::sorted_unique, v); + flat_map fm1(sg14::sorted_unique, v); static_assert(std::is_same_v>); - flat_map fm2 = flat_map(stdext::sorted_unique, std::deque>()); + flat_map fm2 = flat_map(sg14::sorted_unique, std::deque>()); static_assert(std::is_same_v>); std::list> lst; - flat_map fm3(stdext::sorted_unique, lst); + flat_map fm3(sg14::sorted_unique, lst); static_assert(std::is_same_v>); #if __cpp_lib_memory_resource >= 201603 std::pmr::vector> pv; - flat_map fm4(stdext::sorted_unique, pv); + flat_map fm4(sg14::sorted_unique, pv); static_assert(std::is_same_v>); #endif std::initializer_list> il = {{1,"c"}, {3,"b"}, {5,"a"}}; - flat_map fm5(stdext::sorted_unique, il); + flat_map fm5(sg14::sorted_unique, il); static_assert(std::is_same_v>); - assert(( fm5 == decltype(fm5)(stdext::sorted_unique, {{1,"c"}, {3,"b"}, {5,"a"}}) )); + assert(( fm5 == decltype(fm5)(sg14::sorted_unique, {{1,"c"}, {3,"b"}, {5,"a"}}) )); } if (true) { // flat_map(sorted_unique_t, KeyContainer, MappedContainer) std::vector vi {1,2}; std::vector vs {"a","b"}; - flat_map fm1(stdext::sorted_unique, vi, vs); + flat_map fm1(sg14::sorted_unique, vi, vs); static_assert(std::is_same_v>); - assert(( fm1 == decltype(fm1)(stdext::sorted_unique, {{1,"a"}, {2,"b"}}) )); - flat_map fm2(stdext::sorted_unique, std::move(vs), std::move(vi)); + assert(( fm1 == decltype(fm1)(sg14::sorted_unique, {{1,"a"}, {2,"b"}}) )); + flat_map fm2(sg14::sorted_unique, std::move(vs), std::move(vi)); static_assert(std::is_same_v>); - assert(( fm2 == decltype(fm2)(stdext::sorted_unique, {{"a",1}, {"b",2}}) )); + assert(( fm2 == decltype(fm2)(sg14::sorted_unique, {{"a",1}, {"b",2}}) )); } if (true) { // flat_map(sorted_unique_t, Container, Allocator) std::vector> v; - flat_map fm1(stdext::sorted_unique, v, std::allocator()); + flat_map fm1(sg14::sorted_unique, v, std::allocator()); static_assert(std::is_same_v>); #if __cpp_lib_memory_resource >= 201603 std::pmr::vector> pv; // TODO: neither of these lines compiles, and it's unclear what is INTENDED to happen - // flat_map fm2(stdext::sorted_unique, pv, std::allocator()); - // flat_map fm2(stdext::sorted_unique, pv, std::pmr::polymorphic_allocator()); + // flat_map fm2(sg14::sorted_unique, pv, std::allocator()); + // flat_map fm2(sg14::sorted_unique, pv, std::pmr::polymorphic_allocator()); #endif } if (true) { // flat_map(sorted_unique_t, KeyContainer, MappedContainer, Allocator) std::vector vi {2,1}; std::vector vs {"a","b"}; - flat_map fm1(stdext::sorted_unique, vs, vi, std::allocator()); + flat_map fm1(sg14::sorted_unique, vs, vi, std::allocator()); static_assert(std::is_same_v>); - assert(( fm1 == decltype(fm1)(stdext::sorted_unique, {{"a",2}, {"b",1}}) )); + assert(( fm1 == decltype(fm1)(sg14::sorted_unique, {{"a",2}, {"b",1}}) )); #if __cpp_lib_memory_resource >= 201603 std::pmr::vector pvi {1, 2}; std::pmr::vector pvs {"b","a"}; - flat_map fm2(stdext::sorted_unique, pvi, pvs, std::pmr::polymorphic_allocator()); + flat_map fm2(sg14::sorted_unique, pvi, pvs, std::pmr::polymorphic_allocator()); static_assert(std::is_same_v, std::pmr::vector, std::pmr::vector>>); - assert(( fm2 == decltype(fm2)(stdext::sorted_unique, {{1,"b"}, {2,"a"}}) )); + assert(( fm2 == decltype(fm2)(sg14::sorted_unique, {{1,"b"}, {2,"a"}}) )); #endif } if (true) { @@ -420,7 +420,7 @@ TEST(flat_map, DeductionGuides) std::initializer_list> il = {{1,"c"}, {5,"b"}, {3,"a"}}; flat_map fm5(il.begin(), il.end()); static_assert(std::is_same_v>); - assert(( fm5 == decltype(fm5)(stdext::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); + assert(( fm5 == decltype(fm5)(sg14::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); } if (true) { // flat_map(InputIterator, InputIterator, Compare = Compare()) @@ -446,12 +446,12 @@ TEST(flat_map, DeductionGuides) std::initializer_list> il = {{1,"c"}, {5,"b"}, {3,"a"}}; flat_map fm5(il.begin(), il.end(), std::less()); static_assert(std::is_same_v>); - assert(( fm5 == decltype(fm5)(stdext::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); + assert(( fm5 == decltype(fm5)(sg14::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); flat_map fm6(arr, arr + 4, free_function_less); static_assert(std::is_same_v>); assert(fm6.key_comp() == free_function_less); - assert(( fm6 == decltype(fm6)(stdext::sorted_unique, {{1,2}, {2,3}, {3,4}, {4,5}}, free_function_less) )); + assert(( fm6 == decltype(fm6)(sg14::sorted_unique, {{1,2}, {2,3}, {3,4}, {4,5}}, free_function_less) )); } if (true) { // flat_map(InputIterator, InputIterator, Compare, Allocator) @@ -478,12 +478,12 @@ TEST(flat_map, DeductionGuides) std::initializer_list> il = {{1,"c"}, {5,"b"}, {3,"a"}}; flat_map fm5(il.begin(), il.end(), std::less(), std::allocator()); static_assert(std::is_same_v>); - assert(( fm5 == decltype(fm5)(stdext::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); + assert(( fm5 == decltype(fm5)(sg14::sorted_unique, {{1,"c"}, {3,"a"}, {5,"b"}}) )); flat_map fm6(arr, arr + 4, free_function_less, std::allocator()); static_assert(std::is_same_v>); assert(fm6.key_comp() == free_function_less); - assert(( fm6 == decltype(fm6)(stdext::sorted_unique, {{1,2}, {2,3}, {3,4}, {4,5}}, free_function_less) )); + assert(( fm6 == decltype(fm6)(sg14::sorted_unique, {{1,2}, {2,3}, {3,4}, {4,5}}, free_function_less) )); } if (true) { // flat_map(InputIterator, InputIterator, Allocator) @@ -571,12 +571,12 @@ TYPED_TEST(flat_mapt, Construction) } if (std::is_sorted(keys.begin(), keys.end(), Compare())) { for (auto&& fs : { - FS(stdext::sorted_unique, pairs), - FS(stdext::sorted_unique, pairs.begin(), pairs.end()), - FS(stdext::sorted_unique, {{1, "a"}, {3, "c"}, {5, "b"}}), - FS(stdext::sorted_unique, pairs, Compare()), - FS(stdext::sorted_unique, pairs.begin(), pairs.end(), Compare()), - FS(stdext::sorted_unique, {{1, "a"}, {3, "c"}, {5, "b"}}, Compare()), + FS(sg14::sorted_unique, pairs), + FS(sg14::sorted_unique, pairs.begin(), pairs.end()), + FS(sg14::sorted_unique, {{1, "a"}, {3, "c"}, {5, "b"}}), + FS(sg14::sorted_unique, pairs, Compare()), + FS(sg14::sorted_unique, pairs.begin(), pairs.end(), Compare()), + FS(sg14::sorted_unique, {{1, "a"}, {3, "c"}, {5, "b"}}, Compare()), }) { assert(std::is_sorted(fs.keys().begin(), fs.keys().end(), fs.key_comp())); assert(std::is_sorted(fs.begin(), fs.end(), fs.value_comp())); diff --git a/test/flat_set_test.cpp b/test/flat_set_test.cpp index 7a126e8b..bf64de57 100644 --- a/test/flat_set_test.cpp +++ b/test/flat_set_test.cpp @@ -14,14 +14,14 @@ template struct flat_sett : testing::Test {}; using flat_sett_types = testing::Types< - stdext::flat_set // basic - , stdext::flat_set> // custom comparator + sg14::flat_set // basic + , sg14::flat_set> // custom comparator #if __cplusplus >= 201402L - , stdext::flat_set> // transparent comparator + , sg14::flat_set> // transparent comparator #endif - , stdext::flat_set, std::deque> // custom container + , sg14::flat_set, std::deque> // custom container #if __cpp_lib_memory_resource >= 201603 - , stdext::flat_set, std::pmr::vector> // pmr container + , sg14::flat_set, std::pmr::vector> // pmr container #endif >; TYPED_TEST_SUITE(flat_sett, flat_sett_types); @@ -33,8 +33,8 @@ struct AmbiguousEraseWidget { return a.s_ < b.s_; } - using iterator = stdext::flat_set::iterator; - using const_iterator = stdext::flat_set::const_iterator; + using iterator = sg14::flat_set::iterator; + using const_iterator = sg14::flat_set::const_iterator; explicit AmbiguousEraseWidget(const char *s) : s_(s) {} AmbiguousEraseWidget(iterator) : s_("notfound") {} @@ -48,7 +48,7 @@ struct AmbiguousEraseWidget { TEST(flat_set, AmbiguousErase) { - stdext::flat_set fs; + sg14::flat_set fs; fs.emplace("a"); fs.emplace("b"); fs.emplace("c"); @@ -70,7 +70,7 @@ TEST(flat_set, ExtractDoesntSwap) { std::pmr::monotonic_buffer_resource mr; std::pmr::polymorphic_allocator a(&mr); - stdext::flat_set, std::pmr::vector> fs({1, 2}, a); + sg14::flat_set, std::pmr::vector> fs({1, 2}, a); std::pmr::vector v = std::move(fs).extract(); assert(v.get_allocator() == a); assert(fs.empty()); @@ -80,7 +80,7 @@ TEST(flat_set, ExtractDoesntSwap) // Sanity-check with std::allocator, even though this can't fail. { std::allocator a; - stdext::flat_set, std::vector> fs({1, 2}, a); + sg14::flat_set, std::vector> fs({1, 2}, a); std::vector v = std::move(fs).extract(); assert(v.get_allocator() == a); assert(fs.empty()); @@ -111,8 +111,8 @@ bool ComparatorWithThrowingSwap::please_throw = false; TEST(flat_set, ThrowingSwapDoesntBreakInvariants) { using std::swap; - stdext::flat_set fsx({1,2,3}, ComparatorWithThrowingSwap(std::less())); - stdext::flat_set fsy({4,5,6}, ComparatorWithThrowingSwap(std::greater())); + sg14::flat_set fsx({1,2,3}, ComparatorWithThrowingSwap(std::less())); + sg14::flat_set fsy({4,5,6}, ComparatorWithThrowingSwap(std::greater())); if (true) { ComparatorWithThrowingSwap::please_throw = false; @@ -134,7 +134,7 @@ TEST(flat_set, ThrowingSwapDoesntBreakInvariants) TEST(flat_set, VectorBool) { #if __cplusplus >= 201402L // C++11 doesn't support vector::emplace - using FS = stdext::flat_set; + using FS = sg14::flat_set; FS fs; auto it_inserted = fs.emplace(true); assert(it_inserted.second); @@ -171,7 +171,7 @@ struct VectorBoolEvilComparator { TEST(flat_set, VectorBoolEvilComparator) { - using FS = stdext::flat_set; + using FS = sg14::flat_set; FS fs; (void)fs.lower_bound(true); (void)fs.upper_bound(true); @@ -206,7 +206,7 @@ int InstrumentedWidget::copy_ctors = 0; TEST(flat_set, MoveOperationsPilferOwnership) { - using FS = stdext::flat_set; + using FS = sg14::flat_set; InstrumentedWidget::move_ctors = 0; InstrumentedWidget::copy_ctors = 0; FS fs; @@ -283,12 +283,12 @@ TYPED_TEST(flat_sett, Construction) } if (std::is_sorted(vec.begin(), vec.end(), Compare())) { for (auto&& fs : { - FS(stdext::sorted_unique, vec), - FS(stdext::sorted_unique, vec.begin(), vec.end()), - FS(stdext::sorted_unique, {1, 3, 5}), - FS(stdext::sorted_unique, vec, Compare()), - FS(stdext::sorted_unique, vec.begin(), vec.end(), Compare()), - FS(stdext::sorted_unique, {1, 3, 5}, Compare()), + FS(sg14::sorted_unique, vec), + FS(sg14::sorted_unique, vec.begin(), vec.end()), + FS(sg14::sorted_unique, {1, 3, 5}), + FS(sg14::sorted_unique, vec, Compare()), + FS(sg14::sorted_unique, vec.begin(), vec.end(), Compare()), + FS(sg14::sorted_unique, {1, 3, 5}, Compare()), }) { auto cmp = fs.key_comp(); assert(std::is_sorted(fs.begin(), fs.end(), cmp)); diff --git a/test/hive_test.cpp b/test/hive_test.cpp index bdb00b51..b0fff795 100644 --- a/test/hive_test.cpp +++ b/test/hive_test.cpp @@ -3,7 +3,7 @@ #if __cplusplus >= 201703 -#include +#include #include @@ -26,41 +26,41 @@ template struct hivet : testing::Test {}; using hivet_types = testing::Types< - plf::hive - , plf::hive, plf::hive_priority::performance> - , plf::hive, plf::hive_priority::memory_use> - , plf::hive // non-trivial construction/destruction + sg14::hive + , sg14::hive, sg14::hive_priority::performance> + , sg14::hive, sg14::hive_priority::memory_use> + , sg14::hive // non-trivial construction/destruction #if __cpp_lib_memory_resource >= 201603 - , plf::hive> // pmr allocator - , plf::hive> // uses-allocator construction + , sg14::hive> // pmr allocator + , sg14::hive> // uses-allocator construction #endif >; TYPED_TEST_SUITE(hivet, hivet_types); template struct hivet_setup; -template struct hivet_setup> { +template struct hivet_setup> { static unsigned char value(int i) { return i; } static bool int_eq_t(int i, char v) { return v == (unsigned char)(i); } }; -template struct hivet_setup> { +template struct hivet_setup> { static int value(int i) { return i; } static bool int_eq_t(int i, int v) { return v == i; } }; -template struct hivet_setup> { +template struct hivet_setup> { static std::string value(int i) { return std::string("ensure that a memory allocation happens here") + std::to_string(i); } static bool int_eq_t(int i, const std::string& v) { return v == value(i); } }; #if __cpp_lib_memory_resource >= 201603 -template struct hivet_setup> { - static std::pmr::string value(int i) { return hivet_setup>::value(i).c_str(); } - static bool int_eq_t(int i, std::string_view v) { return v == hivet_setup>::value(i); } +template struct hivet_setup> { + static std::pmr::string value(int i) { return hivet_setup>::value(i).c_str(); } + static bool int_eq_t(int i, std::string_view v) { return v == hivet_setup>::value(i); } }; #endif template H make_rope(size_t blocksize, size_t cap) { -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 H h; for (size_t i=0; i < cap; i += blocksize) { H temp; @@ -68,7 +68,7 @@ H make_rope(size_t blocksize, size_t cap) h.splice(temp); } #else - H h(plf::hive_limits(blocksize, blocksize)); + H h(sg14::hive_limits(blocksize, blocksize)); h.reserve(cap); #endif return h; @@ -84,14 +84,14 @@ H make_rope(size_t blocksize, size_t cap) EXPECT_EQ(h.begin().next(h.size()), h.end()); \ EXPECT_EQ(h.end().prev(h.size()), h.begin()); -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS #define EXPECT_DISTANCE(it, jt, n) \ EXPECT_EQ(std::distance(it, jt), n); \ EXPECT_EQ(jt - it, n); \ EXPECT_EQ(it - jt, -n); \ EXPECT_EQ(it + n, jt); \ EXPECT_EQ(jt - n, it); -#elif PLF_HIVE_RELATIONAL_OPERATORS +#elif SG14_HIVE_RELATIONAL_OPERATORS #define EXPECT_DISTANCE(it, jt, n) \ EXPECT_EQ(std::distance(it, jt), n); \ EXPECT_EQ(it.distance(jt), n); \ @@ -108,8 +108,8 @@ H make_rope(size_t blocksize, size_t cap) TEST(hive, OutOfRangeReshapeByP2596) { -#if PLF_HIVE_P2596 - plf::hive h; +#if SG14_HIVE_P2596 + sg14::hive h; h.reshape(0); h.reshape(0, 0); h.reshape(0, h.max_size()); @@ -124,8 +124,8 @@ TEST(hive, OutOfRangeReshapeByP2596) TEST(hive, OutOfRangeLimitsByP0447) { -#if !PLF_HIVE_P2596 - using H = plf::hive; +#if !SG14_HIVE_P2596 + using H = sg14::hive; size_t min = H::block_capacity_hard_limits().min; size_t max = H::block_capacity_hard_limits().max; EXPECT_LE(min, max); @@ -136,11 +136,11 @@ TEST(hive, OutOfRangeLimitsByP0447) // the implementation COULD just clamp them to the possible range. // Instead, P0447R20 says the behavior is undefined. - ASSERT_THROW(H(plf::hive_limits(min-1, max)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(min, max+1)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(min-1, max+1)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(min-1, min)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(max, max+1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min-1, max)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min, max+1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min-1, max+1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min-1, min)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(max, max+1)), std::length_error); H h; ASSERT_THROW(h.reshape({min-1, max}), std::length_error); @@ -153,8 +153,8 @@ TEST(hive, OutOfRangeLimitsByP0447) TEST(hive, OutOfRangeLimitsByMath) { -#if !PLF_HIVE_P2596 - using H = plf::hive; +#if !SG14_HIVE_P2596 + using H = sg14::hive; size_t min = H::block_capacity_hard_limits().min; size_t max = H::block_capacity_hard_limits().max; EXPECT_LE(min, max); @@ -164,10 +164,10 @@ TEST(hive, OutOfRangeLimitsByMath) // These ranges are invalid, or physically impossible to enforce. // P0447R20 says the behavior is undefined in these cases as well. - ASSERT_THROW(H(plf::hive_limits(min-1, min-1)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(max+1, max+1)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(max, max-1)), std::length_error); - ASSERT_THROW(H(plf::hive_limits(min+1, min)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min-1, min-1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(max+1, max+1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(max, max-1)), std::length_error); + ASSERT_THROW(H(sg14::hive_limits(min+1, min)), std::length_error); H h; ASSERT_THROW(h.reshape({min-1, min-1}), std::length_error); @@ -213,7 +213,7 @@ TEST(hive, FirstInsertThrows) struct S { S() { throw 42; } }; - plf::hive h; + sg14::hive h; EXPECT_THROW(h.emplace(), int); EXPECT_EQ(h.size(), 0u); EXPECT_INVARIANTS(h); @@ -233,7 +233,7 @@ TEST(hive, RegressionTestIssue20) }; for (int t = 1; t < 20; ++t) { - plf::hive h = make_rope>(8, 10); + sg14::hive h = make_rope>(8, 10); h.insert(10, S(&should_throw, 42)); auto it = h.begin(); std::advance(it, 3); @@ -266,7 +266,7 @@ TEST(hive, RegressionTestIssue20) S(&should_throw, 5), }; for (int t = 1; t < 20; ++t) { - plf::hive h = make_rope>(8, 10); + sg14::hive h = make_rope>(8, 10); should_throw = 0; h.insert(10, S(&should_throw, 42)); auto it = h.begin(); @@ -294,7 +294,7 @@ TEST(hive, RegressionTestIssue20) TEST(hive, RegressionTestIssue24) { - plf::hive h = {1,2,0,4}; + sg14::hive h = {1,2,0,4}; std::erase(h, 0); auto it = h.begin(); ++it; auto jt = h.begin(); ++jt; ++jt; @@ -303,7 +303,7 @@ TEST(hive, RegressionTestIssue24) TEST(hive, RegressionTestIssue25) { - plf::hive h = {1,0,1}; + sg14::hive h = {1,0,1}; std::erase(h, 0); auto it = h.end(); auto jt = h.end(); --jt; @@ -324,16 +324,16 @@ TEST(hive, ReshapeWithThrow) }; for (int t = 1; t < 20; ++t) { - plf::hive h = make_rope>(9, 20); + sg14::hive h = make_rope>(9, 20); h.insert(20, S(&should_throw, 42)); EXPECT_EQ(h.size(), 20u); -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 EXPECT_EQ(h.block_capacity_limits().min, 9); EXPECT_EQ(h.block_capacity_limits().max, 9); #endif try { should_throw = t; -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 h.reshape(6); #else h.reshape({6, 6}); @@ -351,8 +351,8 @@ TEST(hive, ReshapeWithThrow) TEST(hive, ReshapeUnusedBlocksP2596) { -#if PLF_HIVE_P2596 - plf::hive h = make_rope>(9, 42); +#if SG14_HIVE_P2596 + sg14::hive h = make_rope>(9, 42); h.insert(42, 'x'); h.erase(h.begin(), h.begin().next(20)); EXPECT_EQ(h.size(), 22u); @@ -366,8 +366,8 @@ TEST(hive, ReshapeUnusedBlocksP2596) TEST(hive, ReshapeUnusedBlocks) { -#if !PLF_HIVE_P2596 - plf::hive h = make_rope>(9, 42); +#if !SG14_HIVE_P2596 + sg14::hive h = make_rope>(9, 42); h.insert(42, 'x'); h.erase(h.begin(), h.begin().next(20)); EXPECT_EQ(h.size(), 22u); @@ -382,13 +382,13 @@ TEST(hive, ReshapeUnusedBlocks) TEST(hive, ReshapeUnusedBlocks2) { -#if !PLF_HIVE_P2596 - plf::hive h; +#if !SG14_HIVE_P2596 + sg14::hive h; h.reshape({6, 9}); - h.splice(plf::hive{1,2,3,4,5,6,7,8,9}); - h.splice(plf::hive{1,2,3,4,5,6}); - h.splice(plf::hive{1,2,3,4,5,6}); - h.splice(plf::hive{1,2,3,4,5,6,7,8,9}); + h.splice(sg14::hive{1,2,3,4,5,6,7,8,9}); + h.splice(sg14::hive{1,2,3,4,5,6}); + h.splice(sg14::hive{1,2,3,4,5,6}); + h.splice(sg14::hive{1,2,3,4,5,6,7,8,9}); h.erase(h.begin(), h.begin().next(10)); h.erase(h.end().prev(10), h.end()); EXPECT_EQ(h.size(), 10u); @@ -527,7 +527,7 @@ TYPED_TEST(hivet, CustomDistanceFunction) EXPECT_DISTANCE(plus20, plus200, 180); EXPECT_DISTANCE(plus200, plus200, 0); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ(plus20.distance(h.begin()), -20); EXPECT_EQ(plus200.distance(h.begin()), -200); EXPECT_EQ(plus200.distance(plus20), -180); @@ -541,7 +541,7 @@ TYPED_TEST(hivet, CustomDistanceFunction) EXPECT_DISTANCE(c20, c200, 180); EXPECT_DISTANCE(c200, c200, 0); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ(c20.distance(h.cbegin()), -20); EXPECT_EQ(c200.distance(h.cbegin()), -200); EXPECT_EQ(c200.distance(c20), -180); @@ -674,7 +674,7 @@ TYPED_TEST(hivet, CustomDistanceFunctionRev) EXPECT_DISTANCE(plus20, plus200, 180); EXPECT_DISTANCE(plus200, plus200, 0); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ(plus20.distance(h.rbegin()), -20); EXPECT_EQ(plus200.distance(h.rbegin()), -200); EXPECT_EQ(plus200.distance(plus20), -180); @@ -688,7 +688,7 @@ TYPED_TEST(hivet, CustomDistanceFunctionRev) EXPECT_DISTANCE(c20, c200, 180); EXPECT_DISTANCE(c200, c200, 0); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ(c20.distance(h.crbegin()), -20); EXPECT_EQ(c200.distance(h.crbegin()), -200); EXPECT_EQ(c200.distance(c20), -180); @@ -714,12 +714,12 @@ TYPED_TEST(hivet, CopyConstructor) TEST(hive, MoveConstructor) { - plf::hive h = {1, 2, 3, 4, 5, 6, 7}; + sg14::hive h = {1, 2, 3, 4, 5, 6, 7}; h.insert(10'000, 42); - plf::hive copy = h; + sg14::hive copy = h; - plf::hive h2 = std::move(h); + sg14::hive h2 = std::move(h); EXPECT_TRUE(h.empty()); EXPECT_INVARIANTS(h); EXPECT_EQ(h2.size(), 10'007); @@ -727,7 +727,7 @@ TEST(hive, MoveConstructor) EXPECT_TRUE(std::equal(copy.begin(), copy.end(), h2.begin(), h2.end())); h = copy; - plf::hive h3(std::move(h), copy.get_allocator()); + sg14::hive h3(std::move(h), copy.get_allocator()); EXPECT_TRUE(h.empty()); EXPECT_INVARIANTS(h); EXPECT_EQ(h3.size(), 10'007); @@ -737,7 +737,7 @@ TEST(hive, MoveConstructor) TEST(hive, ReverseIterator) { - plf::hive h = {1, 2, 3, 4, 5}; + sg14::hive h = {1, 2, 3, 4, 5}; std::vector expected = {1, 2, 3, 4, 5}; EXPECT_TRUE(std::equal(h.begin(), h.end(), expected.begin(), expected.end())); EXPECT_TRUE(std::equal(h.cbegin(), h.cend(), expected.begin(), expected.end())); @@ -747,7 +747,7 @@ TEST(hive, ReverseIterator) TEST(hive, ReverseIteratorBase) { - plf::hive h = {1, 2, 3, 4, 5}; + sg14::hive h = {1, 2, 3, 4, 5}; EXPECT_EQ(h.rend().base(), h.begin()); EXPECT_EQ(h.crend().base(), h.cbegin()); EXPECT_EQ(h.rbegin().base(), h.end()); @@ -755,15 +755,15 @@ TEST(hive, ReverseIteratorBase) auto rit = h.rbegin(); auto crit = h.crbegin(); - static_assert(std::is_same::iterator>::value, ""); - static_assert(std::is_same::const_iterator>::value, ""); + static_assert(std::is_same::iterator>::value, ""); + static_assert(std::is_same::const_iterator>::value, ""); static_assert(noexcept(rit.base()), ""); static_assert(noexcept(crit.base()), ""); } TEST(hive, ShrinkToFit) { - plf::hive h = {1, 2, 3, 4, 5}; + sg14::hive h = {1, 2, 3, 4, 5}; size_t oldcap = h.capacity(); h.shrink_to_fit(); EXPECT_EQ(h.size(), 5u); @@ -773,7 +773,7 @@ TEST(hive, ShrinkToFit) TEST(hive, InsertInMovedFromContainer) { - plf::hive h = {1, 2, 3, 4, 5}; + sg14::hive h = {1, 2, 3, 4, 5}; auto dummy = std::move(h); EXPECT_TRUE(h.empty()); h.insert(42); @@ -784,8 +784,8 @@ TEST(hive, InsertInMovedFromContainer) TEST(hive, Swap) { - plf::hive h1 = {1, 2, 3, 4, 5}; - plf::hive h2 = {3, 1, 4}; + sg14::hive h1 = {1, 2, 3, 4, 5}; + sg14::hive h2 = {3, 1, 4}; h1.swap(h2); EXPECT_EQ(h1.size(), 3u); @@ -804,7 +804,7 @@ TEST(hive, Swap) TEST(hive, MaxSize) { - plf::hive h1 = {1, 2, 3, 4, 5}; + sg14::hive h1 = {1, 2, 3, 4, 5}; EXPECT_GE(h1.max_size(), 100'000u); static_assert(noexcept(h1.max_size()), ""); static_assert(std::is_same::value, ""); @@ -812,7 +812,7 @@ TEST(hive, MaxSize) TEST(hive, IteratorConvertibility) { - using H = plf::hive; + using H = sg14::hive; using It = H::iterator; using CIt = H::const_iterator; using RIt = H::reverse_iterator; @@ -855,7 +855,7 @@ template using Tag = typename std::iterator_traits::iterator_categor TEST(hive, IteratorCategory) { - using H = plf::hive; + using H = sg14::hive; using It = H::iterator; using CIt = H::const_iterator; using RIt = H::reverse_iterator; @@ -865,7 +865,7 @@ TEST(hive, IteratorCategory) static_assert(std::is_base_of>::value, ""); static_assert(std::is_base_of>::value, ""); static_assert(std::is_base_of>::value, ""); -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS static_assert(std::is_base_of>::value, ""); static_assert(std::is_base_of>::value, ""); static_assert(std::is_base_of>::value, ""); @@ -881,7 +881,7 @@ TEST(hive, IteratorCategory) #if __cpp_lib_ranges >= 201911 TEST(hive, RangeConcepts) { - using H = plf::hive; + using H = sg14::hive; using It = H::iterator; using CIt = H::const_iterator; using RIt = H::reverse_iterator; @@ -892,7 +892,7 @@ TEST(hive, RangeConcepts) static_assert(std::bidirectional_iterator, ""); static_assert(std::bidirectional_iterator, ""); static_assert(std::ranges::bidirectional_range, ""); -#if PLF_HIVE_RANDOM_ACCESS_ITERATORS +#if SG14_HIVE_RANDOM_ACCESS_ITERATORS static_assert(std::random_access_iterator, ""); static_assert(std::random_access_iterator, ""); static_assert(std::random_access_iterator, ""); @@ -934,7 +934,7 @@ TYPED_TEST(hivet, IteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -955,7 +955,7 @@ TYPED_TEST(hivet, IteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered); #endif @@ -981,7 +981,7 @@ TYPED_TEST(hivet, ConstIteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -1002,7 +1002,7 @@ TYPED_TEST(hivet, ConstIteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered); #endif @@ -1028,7 +1028,7 @@ TYPED_TEST(hivet, MixedIteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -1049,7 +1049,7 @@ TYPED_TEST(hivet, MixedIteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered_with< typename Hive::iterator, @@ -1081,7 +1081,7 @@ TYPED_TEST(hivet, ReverseIteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -1102,7 +1102,7 @@ TYPED_TEST(hivet, ReverseIteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered); #endif @@ -1128,7 +1128,7 @@ TYPED_TEST(hivet, ConstReverseIteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -1149,7 +1149,7 @@ TYPED_TEST(hivet, ConstReverseIteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered); #endif @@ -1175,7 +1175,7 @@ TYPED_TEST(hivet, MixedReverseIteratorComparison) EXPECT_EQ((it2 == it1), false); EXPECT_EQ((it2 != it1), true); -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS EXPECT_EQ((it1 < it2), true); EXPECT_EQ((it1 <= it2), true); EXPECT_EQ((it1 > it2), false); @@ -1196,7 +1196,7 @@ TYPED_TEST(hivet, MixedReverseIteratorComparison) #endif } -#if PLF_HIVE_RELATIONAL_OPERATORS +#if SG14_HIVE_RELATIONAL_OPERATORS #if __cpp_lib_concepts >= 202002 static_assert(std::totally_ordered_with< typename Hive::reverse_iterator, @@ -1214,7 +1214,7 @@ TYPED_TEST(hivet, MixedReverseIteratorComparison) TEST(hive, EraseOne) { - plf::hive h = {1, 2, 3, 4, 5, 6, 7, 8}; + sg14::hive h = {1, 2, 3, 4, 5, 6, 7, 8}; auto erase_one = [&](int i) { auto it = h.begin(); std::advance(it, i); auto rt = h.erase(it); @@ -1236,7 +1236,7 @@ TEST(hive, EraseOne) TEST(hive, EraseTwo) { - plf::hive h = {1, 2, 3, 4, 5, 6, 7, 8}; + sg14::hive h = {1, 2, 3, 4, 5, 6, 7, 8}; auto erase_two = [&](int i, int j) { auto it = h.begin(); std::advance(it, i); auto jt = h.begin(); std::advance(jt, j); @@ -1286,7 +1286,7 @@ TEST(hive, EraseTwo) TEST(hive, InsertAndErase) { std::mt19937 g; - plf::hive h; + sg14::hive h; for (int i = 0; i < 500'000; ++i) { h.insert(i); } @@ -1323,11 +1323,11 @@ TEST(hive, InsertAndErase) TEST(hive, InsertAndErase2) { std::mt19937 g; - plf::hive h; -#if PLF_HIVE_P2596 + sg14::hive h; +#if SG14_HIVE_P2596 h.reshape(10'000, 30'000); #else - h.reshape(plf::hive_limits(10'000, h.block_capacity_limits().max)); + h.reshape(sg14::hive_limits(10'000, h.block_capacity_limits().max)); #endif h.insert(30'000, 1); EXPECT_EQ(h.size(), 30'000u); @@ -1424,7 +1424,7 @@ TEST(hive, InsertAndErase2) TEST(hive, InsertAndErase3) { - plf::hive h(500'000, 10); + sg14::hive h(500'000, 10); auto first = h.begin(); auto last = h.end(); std::advance(first, 300'000); @@ -1470,7 +1470,7 @@ TEST(hive, InsertAndErase3) TEST(hive, Reserve) { - plf::hive h(10); + sg14::hive h(10); size_t cap = h.capacity(); h.reserve(100'000); EXPECT_GE(h.capacity(), 100'000); @@ -1481,7 +1481,7 @@ TEST(hive, Reserve) TEST(hive, MultipleSingleInsertErase) { std::mt19937 g; - plf::hive h(110'000, 1); + sg14::hive h(110'000, 1); size_t count = h.size(); for (int i = 0; i < 50'000; ++i) { @@ -1506,7 +1506,7 @@ TEST(hive, MultipleSingleInsertErase) TEST(hive, Erase) { - plf::hive h; + sg14::hive h; for (int i = 0; i < 1000; ++i) { h.insert(i); } @@ -1556,7 +1556,7 @@ TEST(hive, Erase) TEST(hive, RangeEraseHalfErasedAlternating) { - plf::hive v; + sg14::hive v; for (int i = 0; i < 3000; ++i) { v.insert(i); } @@ -1577,7 +1577,7 @@ TEST(hive, RangeEraseHalfErasedAlternating) TEST(hive, RangeEraseThirdErasedRandomized) { std::mt19937 g; - plf::hive v(3000, 42); + sg14::hive v(3000, 42); for (auto it = v.begin(); it != v.end(); ) { if (g() % 2 == 0) { it = v.erase(it); @@ -1677,7 +1677,7 @@ TYPED_TEST(hivet, EraseEmptyRange) TEST(hive, RegressionTestIssue8) { - plf::hive h = {1,2,3,4,5}; + sg14::hive h = {1,2,3,4,5}; h.erase(h.begin()); h.erase(h.begin()); h.insert(6); @@ -1701,7 +1701,7 @@ TEST(hive, RegressionTestIssue14) }; static_assert(std::is_nothrow_copy_constructible::value, ""); - plf::hive h; + sg14::hive h; int a[] = {1, 2, 3, 4, 5}; ASSERT_THROW(h.assign(a, a + 5), int); EXPECT_INVARIANTS(h); @@ -1723,7 +1723,7 @@ TYPED_TEST(hivet, RegressionTestIssue15) TEST(hive, RegressionTestIssue16) { for (int n = 0; n < 15; ++n) { - plf::hive h = make_rope>(4, n); + sg14::hive h = make_rope>(4, n); h.insert(n, 'x'); for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n - i; ++j) { @@ -1866,7 +1866,7 @@ TYPED_TEST(hivet, ConstructFromIteratorPair) TEST(hive, ConstructFromVectorBoolIteratorPair) { std::vector v = { true, false, true, false, true }; - auto h = plf::hive(v.begin(), v.end()); + auto h = sg14::hive(v.begin(), v.end()); EXPECT_EQ(h.size(), 5u); EXPECT_INVARIANTS(h); EXPECT_EQ(std::count(h.begin(), h.end(), true), 3); @@ -1876,9 +1876,9 @@ TEST(hive, ConstructFromVectorBoolIteratorPair) #if __cpp_lib_ranges >= 201911 && __cpp_lib_ranges_to_container >= 202202 TEST(hive, ConstructFromRange) { - plf::hive v = {1, 2, 3}; + sg14::hive v = {1, 2, 3}; auto r = v | std::views::take(2); - plf::hive h(std::from_range, r); + sg14::hive h(std::from_range, r); EXPECT_EQ(h.size(), 2u); EXPECT_INVARIANTS(h); EXPECT_EQ(*h.begin(), 1); @@ -2039,7 +2039,7 @@ TYPED_TEST(hivet, MoveOnlyInputIterator) TEST(hive, ReserveAndFill) { - plf::hive v; + sg14::hive v; v.trim_capacity(); v.reserve(50'000); v.insert(60'000, 1); @@ -2050,7 +2050,7 @@ TEST(hive, ReserveAndFill) TEST(hive, ReserveAndFill2) { - plf::hive v; + sg14::hive v; v.reserve(50'000); v.insert(60, 1); EXPECT_EQ(v.size(), 60u); @@ -2077,7 +2077,7 @@ TEST(hive, ReserveAndFill2) TEST(hive, Assign) { - plf::hive v(50, 2); + sg14::hive v(50, 2); v.assign(50, 1); EXPECT_EQ(v.size(), 50u); EXPECT_INVARIANTS(v); @@ -2097,7 +2097,7 @@ TEST(hive, Assign) TEST(hive, AssignFuzz) { std::mt19937 g; - plf::hive v; + sg14::hive v; for (int t = 0; t < 10; ++t) { size_t n = g() % 100'000; int x = g() % 20; @@ -2111,7 +2111,7 @@ TEST(hive, AssignFuzz) TEST(hive, AssignOverloads) { int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - plf::hive h; + sg14::hive h; h.assign(a, a + 10); EXPECT_TRUE(std::equal(h.begin(), h.end(), a, a + 10)); EXPECT_INVARIANTS(h); @@ -2150,7 +2150,7 @@ TYPED_TEST(hivet, AssignOverloadsForRanges) TEST(hive, AssignIteratorPairFuzz) { std::mt19937 g; - plf::hive h; + sg14::hive h; for (int t = 0; t < 10; ++t) { size_t n = g() % 100'000; int x = g() % 20; @@ -2169,7 +2169,7 @@ TEST(hive, PerfectForwarding) explicit S(int&&, int& i) : success(true) { i = 1; } }; - plf::hive v; + sg14::hive v; int i = 0; v.emplace(7, i); EXPECT_EQ(v.size(), 1u); @@ -2191,7 +2191,7 @@ TEST(hive, BasicEmplace) explicit S(int n) : number(n) {} }; - plf::hive v; + sg14::hive v; for (int i = 0; i < 100; ++i) { v.emplace(i); } @@ -2206,7 +2206,7 @@ TEST(hive, BasicEmplace) TEST(hive, MoveOnly) { - plf::hive> h; + sg14::hive> h; h.emplace(std::make_unique(1)); h.emplace(std::make_unique(2)); EXPECT_EQ(h.size(), 2u); @@ -2221,7 +2221,7 @@ TEST(hive, NonCopyable) S(const S&) = delete; S& operator=(const S&) = delete; }; - plf::hive h; + sg14::hive h; h.emplace(1); h.emplace(2); EXPECT_EQ(h.size(), 2u); @@ -2232,9 +2232,9 @@ TEST(hive, NonCopyable) TEST(hive, Reshape) { -#if !PLF_HIVE_P2596 - plf::hive h; - h.reshape(plf::hive_limits(50, 100)); +#if !SG14_HIVE_P2596 + sg14::hive h; + h.reshape(sg14::hive_limits(50, 100)); EXPECT_EQ(h.block_capacity_limits().min, 50u); EXPECT_EQ(h.block_capacity_limits().max, 100u); EXPECT_TRUE(h.empty()); @@ -2253,7 +2253,7 @@ TEST(hive, Reshape) EXPECT_INVARIANTS(h); h.clear(); - h.reshape(plf::hive_limits(200, 2000)); + h.reshape(sg14::hive_limits(200, 2000)); EXPECT_TRUE(h.empty()); EXPECT_EQ(h.block_capacity_limits().min, 200u); EXPECT_EQ(h.block_capacity_limits().max, 2000u); @@ -2265,12 +2265,12 @@ TEST(hive, Reshape) EXPECT_INVARIANTS(h); static_assert(noexcept(h.block_capacity_limits()), ""); - plf::hive_limits soft = h.block_capacity_limits(); + sg14::hive_limits soft = h.block_capacity_limits(); EXPECT_EQ(soft.min, 200u); EXPECT_EQ(soft.max, 2000u); static_assert(noexcept(decltype(h)::block_capacity_hard_limits()), ""); - plf::hive_limits hard = decltype(h)::block_capacity_hard_limits(); + sg14::hive_limits hard = decltype(h)::block_capacity_hard_limits(); EXPECT_EQ(hard.min, 3u); EXPECT_EQ(hard.max, 65535u); @@ -2281,14 +2281,14 @@ TEST(hive, Reshape) EXPECT_EQ(h.capacity(), 5200u); EXPECT_INVARIANTS(h); - h.reshape(plf::hive_limits(500, 500)); + h.reshape(sg14::hive_limits(500, 500)); EXPECT_EQ(h.block_capacity_limits().min, 500u); EXPECT_EQ(h.block_capacity_limits().max, 500u); EXPECT_EQ(h.size(), 3301u); EXPECT_EQ(h.capacity(), 3500u); EXPECT_INVARIANTS(h); - h.reshape(plf::hive_limits(200, 200)); + h.reshape(sg14::hive_limits(200, 200)); EXPECT_EQ(h.size(), 3301u); EXPECT_EQ(h.capacity(), 3400u); EXPECT_INVARIANTS(h); @@ -2299,8 +2299,8 @@ TEST(hive, SpliceLvalue) { std::vector v1 = {1, 2, 3}; std::vector v2 = {11, 12}; - plf::hive h1(v1.begin(), v1.end()); - plf::hive h2(v2.begin(), v2.end()); + sg14::hive h1(v1.begin(), v1.end()); + sg14::hive h2(v2.begin(), v2.end()); h1.splice(h2); // lvalue v1.insert(v1.end(), v2.begin(), v2.end()); @@ -2311,7 +2311,7 @@ TEST(hive, SpliceLvalue) static_assert(!noexcept(h1.splice(h2))); -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 // Test the throwing case h1.reshape({5, 5}); h2.reshape({10, 10}); @@ -2329,8 +2329,8 @@ TEST(hive, SpliceRvalue) { std::vector v1 = {1, 2, 3}; std::vector v2 = {11, 12}; - plf::hive h1(v1.begin(), v1.end()); - plf::hive h2(v2.begin(), v2.end()); + sg14::hive h1(v1.begin(), v1.end()); + sg14::hive h2(v2.begin(), v2.end()); h1.splice(std::move(h2)); // rvalue v1.insert(v1.end(), v2.begin(), v2.end()); @@ -2341,7 +2341,7 @@ TEST(hive, SpliceRvalue) static_assert(!noexcept(h1.splice(std::move(h2)))); -#if !PLF_HIVE_P2596 +#if !SG14_HIVE_P2596 // Test the throwing case h1.reshape({5, 5}); h2.reshape({10, 10}); @@ -2367,7 +2367,7 @@ TEST(hive, SpliceProperties) }; if (true) { - plf::hive h; + sg14::hive h; static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -2376,14 +2376,14 @@ TEST(hive, SpliceProperties) // Splice from an empty hive h.emplace(1); - h.splice(plf::hive()); + h.splice(sg14::hive()); EXPECT_EQ(h.size(), 1u); EXPECT_INVARIANTS(h); } if (true) { // Splice to an empty hive - plf::hive h1; - plf::hive h2; + sg14::hive h1; + sg14::hive h2; h2.emplace(2); while (h2.size() != h2.capacity()) { h2.emplace(3); @@ -2418,7 +2418,7 @@ TEST(hive, SpliceProperties) TEST(hive, SpliceLargeRandom) { std::mt19937 g; - plf::hive h1(1000, 1); + sg14::hive h1(1000, 1); for (int t = 0; t < 10; ++t) { for (auto it = h1.begin(); it != h1.end(); ++it) { @@ -2429,7 +2429,7 @@ TEST(hive, SpliceLargeRandom) } EXPECT_INVARIANTS(h1); - plf::hive h2(1000, t); + sg14::hive h2(1000, t); for (auto it = h2.begin(); it != h2.end(); ++it) { if (g() & 1) { it = h2.erase(it); @@ -2454,9 +2454,9 @@ TEST(hive, SpliceLargeRandom) TEST(hive, SpliceRegressionTest) { int a[100] = {}; - plf::hive h; + sg14::hive h; auto s = [&]() { - plf::hive temp; + sg14::hive temp; temp.reserve(100); h.splice(temp); }; @@ -2491,7 +2491,7 @@ TEST(hive, TrimDoesntMove) explicit S(int i) : i(i) {} S(S&&) { throw 42; } }; - plf::hive h = make_rope>(10, 100); + sg14::hive h = make_rope>(10, 100); for (int i=0; i < 100; ++i) { h.emplace(i); } @@ -2520,7 +2520,7 @@ TEST(hive, TrimImmobileType) S& operator=(S&&) = delete; bool operator==(const S& rhs) const { return i_ == rhs.i_; } }; - plf::hive h = make_rope>(4, 100); + sg14::hive h = make_rope>(4, 100); for (int t = 0; t < 100; ++t) { for (int i = 0; i < 100; ++i) { h.emplace(g()); @@ -2567,11 +2567,11 @@ TYPED_TEST(hivet, TrimWhileEmpty) TEST(hive, StdErase) { std::mt19937 g; - plf::hive h1; + sg14::hive h1; for (int count = 0; count != 1000; ++count) { h1.insert(g() & 1); } - plf::hive h2 = h1; + sg14::hive h2 = h1; ASSERT_EQ(h1.size(), 1000u); int count0 = std::count(h1.begin(), h1.end(), 0); @@ -2592,9 +2592,9 @@ TEST(hive, StdErase) TEST(hive, StdErase2) { - auto h = plf::hive(100, 100); + auto h = sg14::hive(100, 100); h.insert(100, 200); - plf::hive h2 = h; + sg14::hive h2 = h; ASSERT_EQ(h.size(), 200u); erase(h, 100); @@ -2616,7 +2616,7 @@ TEST(hive, StdErase2) TEST(hive, StdEraseIf) { - plf::hive h; + sg14::hive h; for (int count = 0; count != 1000; ++count) { h.insert(count); } @@ -2630,7 +2630,7 @@ TEST(hive, StdEraseIf) TEST(hive, ConstexprCtor) { struct S { S() {} }; - static constinit plf::hive h; + static constinit sg14::hive h; EXPECT_TRUE(h.empty()); } #endif @@ -2644,14 +2644,14 @@ struct PmrGuard { TEST(hive, DefaultCtorDoesntAllocate) { - using Hive = plf::hive>; + using Hive = sg14::hive>; PmrGuard guard; Hive h; // should not allocate } TEST(hive, TrimAndSpliceDontAllocate) { - using Hive = plf::hive>; + using Hive = sg14::hive>; Hive h1 = {1,2,3,4,5}; h1.reserve(100); Hive h2 = {1,2,3,4}; @@ -2671,7 +2671,7 @@ TEST(hive, SortDoesntUseAllocator) PmrGuard guard; char buffer[1000]; std::pmr::monotonic_buffer_resource mr(buffer, sizeof buffer); - using Hive = plf::hive>; + using Hive = sg14::hive>; Hive h(&mr); h = {3,1,4,1,5}; @@ -2693,7 +2693,7 @@ TEST(hive, PmrCorrectness) PmrGuard guard; - using Hive = plf::hive>; + using Hive = sg14::hive>; Hive h1(&mr); Hive h2({10, 10}, &mr); Hive h4(100, &mr); @@ -2721,14 +2721,14 @@ TEST(hive, PmrCorrectness) he.insert(100, 42); hf.insert(100, 42); -#if !PLF_HIVE_P2596 - Hive h3(plf::hive_limits(10, 10), &mr); +#if !SG14_HIVE_P2596 + Hive h3(sg14::hive_limits(10, 10), &mr); Hive h5(100, {10, 10}, &mr); - Hive h6(100, plf::hive_limits(10, 10), &mr); + Hive h6(100, sg14::hive_limits(10, 10), &mr); Hive h8(100, 42, {10, 10}, &mr); - Hive h9(100, 42, plf::hive_limits(10, 10), &mr); + Hive h9(100, 42, sg14::hive_limits(10, 10), &mr); Hive hc({1, 2, 3, 4}, {10, 10}, &mr); - Hive hd({1, 2, 3, 4}, plf::hive_limits(10, 10), &mr); + Hive hd({1, 2, 3, 4}, sg14::hive_limits(10, 10), &mr); EXPECT_EQ(h3.size(), 0u); EXPECT_EQ(h5.size(), 100u); @@ -2761,9 +2761,9 @@ TEST(hive, PmrCorrectness) TEST(hive, PmrCorrectReshape) { - plf::hive> h(10); + sg14::hive> h(10); PmrGuard guard; -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 h.reshape(400); #else h.reshape({4, 4}); @@ -2774,9 +2774,9 @@ TEST(hive, PmrCorrectReshape) TEST(hive, PmrCorrectShrinkToFit) { - plf::hive> h(10); + sg14::hive> h(10); PmrGuard guard; -#if PLF_HIVE_P2596 +#if SG14_HIVE_P2596 h.reshape(400); #else h.reshape({4, 4}); @@ -2790,11 +2790,11 @@ TEST(hive, PmrCorrectShrinkToFit) TEST(hive, PmrCorrectAllocAwareCtors) { std::pmr::monotonic_buffer_resource mr(10'000); - plf::hive> h1(10); + sg14::hive> h1(10); { PmrGuard guard; std::pmr::unsynchronized_pool_resource mr(std::pmr::new_delete_resource()); - plf::hive> h2(h1, &mr); + sg14::hive> h2(h1, &mr); EXPECT_EQ(h2.size(), 10u); EXPECT_INVARIANTS(h2); } @@ -2803,7 +2803,7 @@ TEST(hive, PmrCorrectAllocAwareCtors) { PmrGuard guard; std::pmr::unsynchronized_pool_resource mr(std::pmr::new_delete_resource()); - plf::hive> h3(std::move(h1), &mr); + sg14::hive> h3(std::move(h1), &mr); EXPECT_EQ(h3.size(), 10u); EXPECT_INVARIANTS(h3); } @@ -2813,7 +2813,7 @@ TEST(hive, PmrCorrectAllocAwareCtors) TEST(hive, RangeInsertRegressionTest) { - auto h = plf::hive(100, 42); + auto h = sg14::hive(100, 42); h.erase(std::next(h.begin())); h.erase(std::next(h.begin())); EXPECT_EQ(h.size(), 98); diff --git a/test/inplace_function_test.cpp b/test/inplace_function_test.cpp index 2fa43ade..84992aa0 100644 --- a/test/inplace_function_test.cpp +++ b/test/inplace_function_test.cpp @@ -50,7 +50,7 @@ TEST(inplace_function, FunctionPointer) { // Even compatible function pointers require an appropriate amount of "storage". using CompatibleFunctionType = std::remove_reference_t; - stdext::inplace_function fun(&GlobalFunction); + sg14::inplace_function fun(&GlobalFunction); EXPECT_TRUE(bool(fun)); @@ -65,7 +65,7 @@ TEST(inplace_function, FunctionPointer) TEST(inplace_function, Lambda) { - stdext::inplace_function fun; + sg14::inplace_function fun; std::string closure("some closure"); fun = [&closure](int x) { return GlobalFunction(closure, x); }; @@ -80,7 +80,7 @@ TEST(inplace_function, Lambda) TEST(inplace_function, StdBind) { - stdext::inplace_function fun; + sg14::inplace_function fun; std::string closure("some closure"); fun = std::bind(GlobalFunction, closure, std::placeholders::_1); @@ -116,7 +116,7 @@ TEST(inplace_function, FunctorDestruction) AnotherFunctor::mConstructorCalls = 0; { AnotherFunctor ftor; - stdext::inplace_function fun(ftor); + sg14::inplace_function fun(ftor); int r1 = fun(1); int r2 = fun(7); @@ -130,9 +130,9 @@ TEST(inplace_function, FunctorDestruction) AnotherFunctor::mConstructorCalls = 0; { AnotherFunctor ftor; - stdext::inplace_function fun(ftor); - stdext::inplace_function fun2(fun); // copy-ctor - stdext::inplace_function fun3(std::move(fun)); // move-ctor + sg14::inplace_function fun(ftor); + sg14::inplace_function fun2(fun); // copy-ctor + sg14::inplace_function fun3(std::move(fun)); // move-ctor fun3 = fun2; // copy-asgn fun3 = std::move(fun2); // move-asgn } @@ -146,8 +146,8 @@ TEST(inplace_function, Swapping) { AnotherFunctor ftor; auto lambda = [](int x){ return x + 10; }; - stdext::inplace_function fun(ftor); - stdext::inplace_function fun2(lambda); + sg14::inplace_function fun(ftor); + sg14::inplace_function fun2(lambda); fun.swap(fun2); // swap... fun2.swap(fun); // ...and swap back @@ -170,8 +170,8 @@ TEST(inplace_function, Copying) auto sptr = std::make_shared(42); EXPECT_EQ(1, sptr.use_count()); - stdext::inplace_function fun1 = [sptr]() { return *sptr; }; - stdext::inplace_function fun2; + sg14::inplace_function fun1 = [sptr]() { return *sptr; }; + sg14::inplace_function fun2; EXPECT_EQ(2, sptr.use_count()); EXPECT_TRUE(bool(fun1)); @@ -203,7 +203,7 @@ TEST(inplace_function, ContainingStdFunction) return int(offset1 + offset2 + offset3 + str1.length() + str.length()); }; - stdext::inplace_function fun = stdfun; + sg14::inplace_function fun = stdfun; int r = fun("123"); EXPECT_EQ(r, int(offset1 + offset2 + offset3 + str1.length() + 3)); @@ -214,9 +214,9 @@ TEST(inplace_function, SimilarTypeCopy) auto sptr = std::make_shared(42); EXPECT_EQ(1, sptr.use_count()); - stdext::inplace_function fun1 = [sptr]() { return *sptr; }; - stdext::inplace_function fun2(fun1); // fun1 is bigger than 17, but we should be smart about it - stdext::inplace_function fun3; + sg14::inplace_function fun1 = [sptr]() { return *sptr; }; + sg14::inplace_function fun2(fun1); // fun1 is bigger than 17, but we should be smart about it + sg14::inplace_function fun3; EXPECT_EQ(3, sptr.use_count()); EXPECT_FALSE(fun3); @@ -231,15 +231,15 @@ TEST(inplace_function, SimilarTypeCopy) fun3 = nullptr; EXPECT_EQ(1, sptr.use_count()); - stdext::inplace_function fun4; + sg14::inplace_function fun4; fun4 = fun1; // fun1 is bigger than 17, but we should be smart about it } TEST(inplace_function, AssignmentFromDifferentFunctor) { int calls = 0; - stdext::inplace_function add = [&calls] (int a, int b) { ++calls; return a+b; }; - stdext::inplace_function mul = [&calls] (int a, int b) { ++calls; return a*b; }; + sg14::inplace_function add = [&calls] (int a, int b) { ++calls; return a+b; }; + sg14::inplace_function mul = [&calls] (int a, int b) { ++calls; return a*b; }; int r1 = add(3, 5); EXPECT_EQ(8, r1); @@ -296,7 +296,7 @@ int ThrowingFunctor::called = 0; TEST(inplace_function, ExceptionSafety) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; ThrowingFunctor tf; EXPECT_EQ(ThrowingFunctor::constructed, 1); EXPECT_EQ(ThrowingFunctor::destructed, 0); @@ -349,18 +349,18 @@ static constexpr size_t expected_alignment_for_capacity() TEST(inplace_function, StructLayout) { - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<1>(), ""); - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<2>(), ""); - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<4>(), ""); - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<8>(), ""); - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<16>(), ""); - static_assert(std::alignment_of< stdext::inplace_function >::value == expected_alignment_for_capacity<32>(), ""); - static_assert(sizeof( stdext::inplace_function ) == 2 * sizeof(void*), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<1>(), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<2>(), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<4>(), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<8>(), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<16>(), ""); + static_assert(std::alignment_of< sg14::inplace_function >::value == expected_alignment_for_capacity<32>(), ""); + static_assert(sizeof( sg14::inplace_function ) == 2 * sizeof(void*), ""); } TEST(inplace_function, ConvertibleFromNullptr) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; auto nil = nullptr; const auto cnil = nullptr; @@ -399,7 +399,7 @@ struct oon_functor { TEST(inplace_function, ADLProofOperatorNew) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; oon_functor oon(42); IPF fun = oon; IPF fun2; @@ -410,7 +410,7 @@ TEST(inplace_function, ADLProofOperatorNew) TEST(inplace_function, MoveConstructionIsNoexcept) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; std::vector vec; vec.push_back(Functor()); copied = 0; @@ -422,8 +422,8 @@ TEST(inplace_function, MoveConstructionIsNoexcept) TEST(inplace_function, MoveConstructionFromSmallerIsNoexcept) { - using IPF32 = stdext::inplace_function; - using IPF40 = stdext::inplace_function; + using IPF32 = sg14::inplace_function; + using IPF40 = sg14::inplace_function; static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_assignable::value, ""); static_assert(std::is_nothrow_constructible::value, ""); @@ -433,19 +433,19 @@ TEST(inplace_function, MoveConstructionFromSmallerIsNoexcept) // https://bugs.llvm.org/show_bug.cgi?id=32072 struct test_bug_32072_C; struct test_bug_32072 { - stdext::inplace_function m; + sg14::inplace_function m; }; static_assert(std::is_copy_constructible::value, ""); static_assert(std::is_nothrow_move_constructible::value, ""); TEST(inplace_function, RvalueRefParameter) { - stdext::inplace_function&&)> f; + sg14::inplace_function&&)> f; f = [](std::unique_ptr) {}; f = [](std::unique_ptr&&) {}; f = [](const std::unique_ptr&) {}; f(std::make_unique(42)); - stdext::inplace_function)> g; + sg14::inplace_function)> g; g = [](std::unique_ptr) {}; g = [](std::unique_ptr&&) {}; g = [](const std::unique_ptr&) {}; @@ -454,10 +454,10 @@ TEST(inplace_function, RvalueRefParameter) TEST(inplace_function, IsConvertibleTrait) { - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); } TEST(inplace_function, ConvertibleFromQualifiedCallOperator) @@ -470,14 +470,14 @@ TEST(inplace_function, ConvertibleFromQualifiedCallOperator) struct NonconstOnlyCallable { void operator()() {} void operator()() const = delete; }; struct LvalueConstCallable { void operator()() const & {} }; struct NoexceptCallable { void operator()() noexcept {} }; - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); } TEST(inplace_function, ConvertibleFromLambda) @@ -488,39 +488,39 @@ TEST(inplace_function, ConvertibleFromLambda) }; const auto a = []() -> int { return 3; }; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); const auto b = [](int&) -> void {}; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); const auto c = [](int, NoDefaultCtor) -> int { return 3; }; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); const auto d = []() -> void {}; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); - static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); // Same as a, but not const. auto e = []() -> int { return 3; }; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); // Same as a, but not const and mutable. auto f = []() mutable -> int { return 3; }; - static_assert(std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); - static_assert(!std::is_convertible>::value, ""); + static_assert(std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); + static_assert(!std::is_convertible>::value, ""); } namespace { @@ -541,8 +541,8 @@ int InstrumentedCopyConstructor::moves = 0; TEST(inplace_function, ReturnByMove) { - using IPF20 = stdext::inplace_function; - using IPF40 = stdext::inplace_function; + using IPF20 = sg14::inplace_function; + using IPF40 = sg14::inplace_function; static_assert(std::is_convertible::value, ""); static_assert(std::is_convertible::value, ""); static_assert(std::is_convertible::value, ""); @@ -571,7 +571,7 @@ TEST(inplace_function, IsInvocableTrait) using C_Int2 = int(int); using C_Void = void(int&); - using stdext::inplace_function_detail::is_invocable_r; + using sg14::inplace_function_detail::is_invocable_r; static_assert(is_invocable_r::value, ""); static_assert(! is_invocable_r::value, ""); @@ -605,24 +605,24 @@ TEST(inplace_function, IsInvocableTrait) static_assert(is_invocable_r::value, ""); } -static int overloaded_function(stdext::inplace_function) { return 1; } -static int overloaded_function(stdext::inplace_function) { return 2; } +static int overloaded_function(sg14::inplace_function) { return 1; } +static int overloaded_function(sg14::inplace_function) { return 2; } TEST(inplace_function, OverloadingOnArity) { EXPECT_EQ(overloaded_function([]() { return 0; }), 1); EXPECT_EQ(overloaded_function([](int) { return 0; }), 2); } -static int overloaded_function2(stdext::inplace_function) { return 1; } -static int overloaded_function2(stdext::inplace_function) { return 2; } +static int overloaded_function2(sg14::inplace_function) { return 1; } +static int overloaded_function2(sg14::inplace_function) { return 2; } TEST(inplace_function, OverloadingOnParameterType) { EXPECT_EQ(overloaded_function2([](int) { return 0; }), 1); EXPECT_EQ(overloaded_function2([](int*) { return 0; }), 2); } -static int overloaded_function3(stdext::inplace_function) { return 1; } -static int overloaded_function3(stdext::inplace_function) { return 2; } +static int overloaded_function3(sg14::inplace_function) { return 1; } +static int overloaded_function3(sg14::inplace_function) { return 2; } TEST(inplace_function, OverloadingOnReturnType) { EXPECT_EQ(overloaded_function3([](int) { return 0; }), 1); @@ -631,7 +631,7 @@ TEST(inplace_function, OverloadingOnReturnType) TEST(inplace_function, Traits) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; static_assert(std::is_nothrow_default_constructible::value, ""); static_assert(std::is_copy_constructible::value, ""); static_assert(std::is_move_constructible::value, ""); @@ -644,7 +644,7 @@ TEST(inplace_function, Traits) #endif static_assert(std::is_nothrow_destructible::value, ""); - using IPF40 = stdext::inplace_function; // the default is 32 + using IPF40 = sg14::inplace_function; // the default is 32 static_assert(std::is_constructible::value, ""); static_assert(std::is_constructible::value, ""); // TODO: nothrow static_assert(std::is_assignable::value, ""); @@ -660,7 +660,7 @@ TEST(inplace_function, Traits) TEST(inplace_function, DefaultConstructor) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; IPF func; assert(!func); @@ -672,7 +672,7 @@ TEST(inplace_function, DefaultConstructor) TEST(inplace_function, Assignment) { - using IPF = stdext::inplace_function; + using IPF = sg14::inplace_function; IPF func; diff --git a/test/ring_test.cpp b/test/ring_span_test.cpp similarity index 99% rename from test/ring_test.cpp rename to test/ring_span_test.cpp index 7a17dd79..c1528283 100644 --- a/test/ring_test.cpp +++ b/test/ring_span_test.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/test/slot_map_test.cpp b/test/slot_map_test.cpp index fd473da0..d1fcc243 100644 --- a/test/slot_map_test.cpp +++ b/test/slot_map_test.cpp @@ -115,7 +115,7 @@ struct Monad> { } // namespace template class Container> -static void print_slot_map(const stdext::slot_map& sm) +static void print_slot_map(const sg14::slot_map& sm) { printf("%d slots:", (int)sm.slots_.size()); for (auto&& slot : sm.slots_) { @@ -338,7 +338,7 @@ void VerifyCapacityExists(Bool expected) TEST(slot_map, MemberTypedefs) { if (true) { - using SM = stdext::slot_map; + using SM = sg14::slot_map; static_assert(std::is_same>::value, ""); static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -356,7 +356,7 @@ TEST(slot_map, MemberTypedefs) static_assert(std::is_same::value, ""); } if (true) { - using SM = stdext::slot_map; + using SM = sg14::slot_map; static_assert(std::is_same>::value, ""); static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -374,7 +374,7 @@ TEST(slot_map, MemberTypedefs) static_assert(std::is_same::value, ""); } if (true) { - using SM = stdext::slot_map; + using SM = sg14::slot_map; static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -392,7 +392,7 @@ TEST(slot_map, MemberTypedefs) static_assert(std::is_same::value, ""); } if (true) { - using SM = stdext::slot_map, TestContainer::Vector>; + using SM = sg14::slot_map, TestContainer::Vector>; static_assert(std::is_same>::value, ""); static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -411,7 +411,7 @@ TEST(slot_map, MemberTypedefs) } #if __cplusplus >= 201703L if (true) { - using SM = stdext::slot_map; + using SM = sg14::slot_map; static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); static_assert(std::is_same::value, ""); @@ -515,7 +515,7 @@ static void IndexesAreUsedEvenlyTest() TEST(slot_map, Basic) { // Test the most basic slot_map. - using slot_map_1 = stdext::slot_map; + using slot_map_1 = sg14::slot_map; static_assert(std::is_nothrow_move_constructible::value, "preserve nothrow-movability of vector"); BasicTests(42, 37); BoundsCheckingTest(); @@ -532,7 +532,7 @@ TEST(slot_map, Basic) TEST(slot_map, CustomKeyType) { // Test slot_map with a custom key type (C++14 destructuring). - using slot_map_2 = stdext::slot_map; + using slot_map_2 = sg14::slot_map; BasicTests(425, 375); BoundsCheckingTest(); FullContainerStressTest([]() { return 42; }); @@ -546,7 +546,7 @@ TEST(slot_map, CustomKeyType) #if __cplusplus >= 201703L // Test slot_map with a custom key type (C++17 destructuring). - using slot_map_3 = stdext::slot_map; + using slot_map_3 = sg14::slot_map; BasicTests(42, 37); BoundsCheckingTest(); FullContainerStressTest([]() { return 42; }); @@ -563,7 +563,7 @@ TEST(slot_map, CustomKeyType) TEST(slot_map, DequeContainer) { // Test slot_map with a custom (but standard and random-access) container type. - using slot_map_4 = stdext::slot_map, std::deque>; + using slot_map_4 = sg14::slot_map, std::deque>; BasicTests(415, 315); BoundsCheckingTest(); FullContainerStressTest([]() { return 37; }); @@ -579,7 +579,7 @@ TEST(slot_map, DequeContainer) TEST(slot_map, CustomRAContainer) { // Test slot_map with a custom (non-standard, random-access) container type. - using slot_map_5 = stdext::slot_map, TestContainer::Vector>; + using slot_map_5 = sg14::slot_map, TestContainer::Vector>; static_assert(!std::is_nothrow_move_constructible::value, "preserve non-nothrow-movability of Vector"); BasicTests(415, 315); BoundsCheckingTest(); @@ -596,7 +596,7 @@ TEST(slot_map, CustomRAContainer) TEST(slot_map, CustomBidiContainer) { // Test slot_map with a custom (standard, bidirectional-access) container type. - using slot_map_6 = stdext::slot_map, std::list>; + using slot_map_6 = sg14::slot_map, std::list>; static_assert(std::is_nothrow_move_constructible::value == std::is_nothrow_move_constructible>::value, "preserve implementation-defined nothrow-movability of std::list"); BasicTests(415, 315); @@ -615,7 +615,7 @@ TEST(slot_map, MoveOnlyValueType) { // Test slot_map with a move-only value_type. // Sadly, standard containers do not propagate move-only-ness, so we must use our custom Vector instead. - using slot_map_7 = stdext::slot_map, std::pair, TestContainer::Vector>; + using slot_map_7 = sg14::slot_map, std::pair, TestContainer::Vector>; static_assert(std::is_move_constructible::value, ""); static_assert(std::is_move_assignable::value, ""); static_assert(! std::is_copy_constructible::value, ""); diff --git a/test/uninitialized_test.cpp b/test/uninitialized_test.cpp index b7bc3b8b..62e9f62e 100644 --- a/test/uninitialized_test.cpp +++ b/test/uninitialized_test.cpp @@ -46,12 +46,12 @@ TEST(uninitialized_value_construct, Basic) auto m = (lifetest*)malloc(sizeof(lifetest) * n); lifetest::reset(); - stdext::uninitialized_value_construct(m, m + n); + sg14::uninitialized_value_construct(m, m + n); ASSERT_EQ(lifetest::construct, n); ASSERT_EQ(lifetest::destruct, 0); ASSERT_EQ(lifetest::move, 0); - stdext::destruct(m, m + n); + sg14::destroy(m, m + n); ASSERT_EQ(lifetest::construct, n); ASSERT_EQ(lifetest::destruct, n); ASSERT_EQ(lifetest::move, 0); @@ -60,7 +60,7 @@ TEST(uninitialized_value_construct, Basic) } auto m = (int*)malloc(sizeof(int) * 5); - stdext::uninitialized_value_construct(m, m + 5); + sg14::uninitialized_value_construct(m, m + 5); assert(std::all_of(m, m + 5, [](int x) { return x == 0; })); free(m); } @@ -71,18 +71,18 @@ TEST(uninitialized_default_construct, Basic) auto mem1 = (lifetest*)malloc(sizeof(lifetest) * n); lifetest::reset(); - stdext::uninitialized_default_construct(mem1, mem1 + n); + sg14::uninitialized_default_construct(mem1, mem1 + n); ASSERT_EQ(lifetest::construct, n); ASSERT_EQ(lifetest::destruct, 0); ASSERT_EQ(lifetest::move, 0); auto mem2 = (lifetest*)malloc(sizeof(lifetest) * n); - stdext::uninitialized_move(mem1, mem1 + n, mem2); + sg14::uninitialized_move(mem1, mem1 + n, mem2); ASSERT_EQ(lifetest::construct, n); ASSERT_EQ(lifetest::destruct, 0); ASSERT_EQ(lifetest::move, n); - stdext::destruct(mem2, mem2 + n); + sg14::destroy(mem2, mem2 + n); ASSERT_EQ(lifetest::construct, n); ASSERT_EQ(lifetest::destruct, n); ASSERT_EQ(lifetest::move, n); diff --git a/test/unstable_remove_test.cpp b/test/unstable_remove_test.cpp index c20f4cb6..31e4851e 100644 --- a/test/unstable_remove_test.cpp +++ b/test/unstable_remove_test.cpp @@ -35,15 +35,15 @@ TEST(unstable_remove, all) auto partitionfn = [&](std::vector& f) { - stdext::partition(f.begin(), f.end(), cmp); + std::partition(f.begin(), f.end(), cmp); }; auto unstablefn = [&](std::vector& f) { - stdext::unstable_remove_if(f.begin(), f.end(), cmp); + (void)sg14::unstable_remove_if(f.begin(), f.end(), cmp); }; auto removefn = [&](std::vector& f) { - stdext::remove_if(f.begin(), f.end(), cmp); + (void)std::remove_if(f.begin(), f.end(), cmp); }; auto time = [&](auto&& f) {