Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions include/svs/core/data/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,31 +648,32 @@ struct BlockingParameters {
std::optional<lib::PowerOfTwo> blocksize_elements = std::nullopt;
};

template <typename Alloc> class Blocked {
template <typename Alloc> class Blocked : public Alloc {
public:
using allocator_type = Alloc;
const allocator_type& get_allocator() const { return allocator_; }
using value_type = typename std::allocator_traits<allocator_type>::value_type;
const allocator_type& get_allocator() const { return *this; }
Comment thread
rfsaliev marked this conversation as resolved.
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 <typename U> friend class Blocked;
template <typename U>
Blocked(const Blocked<U>& other)
: parameters_{other.parameters_}
, allocator_{other.allocator_} {}
: allocator_type{other.get_allocator()}
, parameters_{other.parameters_} {}

private:
BlockingParameters parameters_{};
Alloc allocator_{};
};

template <typename Alloc> inline constexpr bool is_blocked_v = false;
Expand Down
12 changes: 10 additions & 2 deletions tests/svs/core/data/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>;
struct I {
using value_type = int;
int value;
I(int v = 0)
: value(v) {}
operator int() const { return value; }
};
Comment thread
rfsaliev marked this conversation as resolved.

using T = svs::data::Blocked<I>;
using P = svs::data::BlockingParameters;
auto x = T();
CATCH_REQUIRE(x.get_allocator() == 0); // Default constructed integer.
Expand Down
Loading