diff --git a/include/svs/core/data/simple.h b/include/svs/core/data/simple.h index 819a330d..33335621 100644 --- a/include/svs/core/data/simple.h +++ b/include/svs/core/data/simple.h @@ -648,31 +648,32 @@ struct BlockingParameters { std::optional blocksize_elements = std::nullopt; }; -template class Blocked { +template class Blocked : public Alloc { public: using allocator_type = Alloc; - const allocator_type& get_allocator() const { return allocator_; } + using value_type = typename std::allocator_traits::value_type; + const allocator_type& get_allocator() const { return *this; } const BlockingParameters& parameters() const { return parameters_; } constexpr Blocked() = default; explicit Blocked(const allocator_type& alloc) - : allocator_{alloc} {} + : allocator_type{alloc} {} explicit Blocked(const BlockingParameters& parameters) - : parameters_{parameters} {} + : allocator_type{} + , parameters_{parameters} {} explicit Blocked(const BlockingParameters& parameters, const allocator_type& alloc) - : parameters_{parameters} - , allocator_{alloc} {} + : allocator_type{alloc} + , parameters_{parameters} {} // Enable rebinding of allocators. template friend class Blocked; template Blocked(const Blocked& other) - : parameters_{other.parameters_} - , allocator_{other.allocator_} {} + : allocator_type{other.get_allocator()} + , parameters_{other.parameters_} {} private: BlockingParameters parameters_{}; - Alloc allocator_{}; }; template inline constexpr bool is_blocked_v = false; diff --git a/tests/svs/core/data/block.cpp b/tests/svs/core/data/block.cpp index 4ce42d45..1702c013 100644 --- a/tests/svs/core/data/block.cpp +++ b/tests/svs/core/data/block.cpp @@ -197,10 +197,18 @@ CATCH_TEST_CASE("Testing Blocked Data", "[core][data][blocked]") { } CATCH_SECTION("Blocked Allocator") { - // Use an integer for the "allocator" to test value propagation. + // Use a simple integer-valued struct for the "allocator" to test value propagation. // Since the `Blocked` class doesn't actually use the allocator, this is okay // for functionality testing. - using T = svs::data::Blocked; + struct I { + using value_type = int; + int value; + I(int v = 0) + : value(v) {} + operator int() const { return value; } + }; + + using T = svs::data::Blocked; using P = svs::data::BlockingParameters; auto x = T(); CATCH_REQUIRE(x.get_allocator() == 0); // Default constructed integer.