From 1e92d9f54510bc1fdda0c880a142db29cb46913b Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Fri, 21 Apr 2023 13:33:18 -0700 Subject: [PATCH] Refactor stateful_allocator to test helpers --- test/cfoa/constructor_tests.cpp | 28 ---------------------------- test/cfoa/helpers.hpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/cfoa/constructor_tests.cpp b/test/cfoa/constructor_tests.cpp index 39fbc76a..1256fa7e 100644 --- a/test/cfoa/constructor_tests.cpp +++ b/test/cfoa/constructor_tests.cpp @@ -44,34 +44,6 @@ template struct soccc_allocator bool operator!=(soccc_allocator const& rhs) const { return x_ != rhs.x_; } }; -template struct stateful_allocator -{ - int x_ = -1; - - using value_type = T; - - stateful_allocator() = default; - stateful_allocator(stateful_allocator const&) = default; - stateful_allocator(stateful_allocator&&) = default; - - stateful_allocator(int const x) : x_{x} {} - - template - stateful_allocator(stateful_allocator const& rhs) : x_{rhs.x_} - { - } - - T* allocate(std::size_t n) - { - return static_cast(::operator new(n * sizeof(T))); - } - - void deallocate(T* p, std::size_t) { ::operator delete(p); } - - bool operator==(stateful_allocator const& rhs) const { return x_ == rhs.x_; } - bool operator!=(stateful_allocator const& rhs) const { return x_ != rhs.x_; } -}; - using hasher = stateful_hash; using key_equal = stateful_key_equal; using allocator_type = stateful_allocator >; diff --git a/test/cfoa/helpers.hpp b/test/cfoa/helpers.hpp index e630cd9c..8323393f 100644 --- a/test/cfoa/helpers.hpp +++ b/test/cfoa/helpers.hpp @@ -103,6 +103,34 @@ struct stateful_key_equal } }; +template struct stateful_allocator +{ + int x_ = -1; + + using value_type = T; + + stateful_allocator() = default; + stateful_allocator(stateful_allocator const&) = default; + stateful_allocator(stateful_allocator&&) = default; + + stateful_allocator(int const x) : x_{x} {} + + template + stateful_allocator(stateful_allocator const& rhs) : x_{rhs.x_} + { + } + + T* allocate(std::size_t n) + { + return static_cast(::operator new(n * sizeof(T))); + } + + void deallocate(T* p, std::size_t) { ::operator delete(p); } + + bool operator==(stateful_allocator const& rhs) const { return x_ == rhs.x_; } + bool operator!=(stateful_allocator const& rhs) const { return x_ != rhs.x_; } +}; + struct raii { static std::atomic default_constructor;