Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 5, 2024
1 parent b2cc936 commit c129fb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inc/mkn/kul/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ template <typename T>
std::vector<T, Allocator<T>>& as_super(std::vector<T, NonConstructingAllocator<T>>& v) {
return *reinterpret_cast<std::vector<T, Allocator<T>>*>(&v);
}
template <typename T>
std::vector<T, Allocator<T>> const& as_super(std::vector<T, NonConstructingAllocator<T>> const& v) {
return *reinterpret_cast<std::vector<T, Allocator<T>> const*>(&v);
}

} // namespace mkn::kul

Expand Down
11 changes: 11 additions & 0 deletions test/test/no_construct_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ auto copy_operator_equal(V const& v) {
return out;
}

template <typename V>
auto copy_operator_equal_super(V const& v) {
KUL_DBG_FUNC_ENTER;
V out;
out.reserve(v.capacity());
mkn::kul::as_super(out) = mkn::kul::as_super(v);
return out;
}

template <typename V>
auto copy_manual(V const& v) {
KUL_DBG_FUNC_ENTER;
Expand Down Expand Up @@ -78,11 +87,13 @@ void do_compare() {
auto const v1 = copy_construct(no_construct_vec);
auto const v2 = copy_manual(std_vec);
auto const v3 = copy_manual(no_construct_vec);
auto const v4 = copy_operator_equal_super(no_construct_vec);

if (v0 != std_vec) throw std::runtime_error("FAIL 0");
if (v0 == v1) throw std::runtime_error("FAIL 1"); // :(
if (v0 != v2) throw std::runtime_error("FAIL 2");
if (v0 != v3) throw std::runtime_error("FAIL 3");
if (v0 != v4) throw std::runtime_error("FAIL 4");
}

TEST(NoConstructAllocator, copies) { do_compare<S<8>>(); }

0 comments on commit c129fb6

Please sign in to comment.