Skip to content

Commit

Permalink
fix const
Browse files Browse the repository at this point in the history
  • Loading branch information
wusatosi committed Nov 26, 2024
1 parent 541ad68 commit 6b75318
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <typename T, std::size_t Capacity>
struct inplace_vector_bytes_based_storage {
alignas(T) std::array<std::byte, Capacity * sizeof(T)> elems;

T *begin() { return std::launder(reinterpret_cast<const T *>(elems.data())); }
T *begin() { return std::launder(reinterpret_cast<T *>(elems.data())); }
const T *begin() const {
return std::launder(reinterpret_cast<const T *>(elems.data()));
}
Expand Down Expand Up @@ -605,7 +605,8 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
#else
// Note: placement-new may not be constexpr friendly
// Avoiding placement-new may allow inplace_vector to be constexpr friendly
auto final = ::new (end()) T(std::forward<Args>(args)...);
// cast to void* here to adapt to a const T
auto final = ::new ((void *)end()) T(std::forward<Args>(args)...);
#endif
this->change_size(1);
return *final;
Expand Down
2 changes: 1 addition & 1 deletion tests/beman/inplace_vector/inplace_vector.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace beman::inplace_vector;
struct NonTrivial {
int z = 5;

bool operator==(NonTrivial const &other) { return this->z == other.z; }
bool operator==(NonTrivial const &other) const { return this->z == other.z; }
};
static_assert(!std::is_trivial_v<NonTrivial>);

Expand Down

0 comments on commit 6b75318

Please sign in to comment.