Skip to content

Commit

Permalink
Merge branch 'sshirokov/83_any' of https://github.com/OpenCyphal/CETL
Browse files Browse the repository at this point in the history
…into sshirokov/83_any
  • Loading branch information
Sergei Shirokov authored and Sergei Shirokov committed Mar 25, 2024
2 parents 1e6e5db + 6a315ce commit fb88cf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 4 additions & 0 deletions cetlvast/suites/unittest/test_any.cpp
Expand Up @@ -14,6 +14,8 @@
#include <utility>
#include <gtest/gtest.h>

// NOLINTBEGIN(*-use-after-move)

namespace
{

Expand Down Expand Up @@ -907,3 +909,5 @@ TEST(test_any, emplace_2_initializer_list)
}

} // namespace

// NOLINTEND(*-use-after-move)
32 changes: 15 additions & 17 deletions include/cetl/any.hpp
Expand Up @@ -27,23 +27,8 @@ namespace detail
{

template <std::size_t Footprint, std::size_t Alignment>
struct base_storage
struct base_storage // NOLINT(*-pro-type-member-init)
{
private:
// We need to align the buffer to the given value (maximum alignment by default).
// Also, we need to ensure that the buffer is at least 1 byte long.
alignas(Alignment) char buffer_[std::max(Footprint, 1UL)];

// Holds type-erased value destroyer. `nullptr` if storage has no value stored.
void (*value_destroyer_)(void* self) = nullptr;

public:
// Holds type-erased value copyer. `nullptr` when copy operation is not supported.
void (*value_copier_)(const void* src, void* dst) = nullptr;

// Holds type-erased value mover. `nullptr` when move operation is not supported.
void (*value_mover_)(void* src, void* dst) = nullptr;

base_storage() = default;

CETL_NODISCARD void* get_raw_storage() noexcept
Expand Down Expand Up @@ -115,6 +100,19 @@ struct base_storage
value_mover_ = nullptr;
}

// Holds type-erased value copyer. `nullptr` when copy operation is not supported.
void (*value_copier_)(const void* src, void* dst) = nullptr;

// Holds type-erased value mover. `nullptr` when move operation is not supported.
void (*value_mover_)(void* src, void* dst) = nullptr;

private:
// We need to align the buffer to the given value (maximum alignment by default).
// Also, we need to ensure that the buffer is at least 1 byte long.
alignas(Alignment) char buffer_[std::max(Footprint, 1UL)];

// Holds type-erased value destroyer. `nullptr` if storage has no value stored.
void (*value_destroyer_)(void* self) = nullptr;
}; // base_storage

// Copy policy.
Expand Down Expand Up @@ -280,7 +278,7 @@ class any : detail::base_move<Footprint, Copyable, Movable, Alignment>
typename ValueType,
typename Tp = std::decay_t<ValueType>,
typename = std::enable_if_t<!std::is_same<Tp, any>::value && !pf17::detail::is_in_place_type<ValueType>::value>>
any(ValueType&& value)
any(ValueType&& value) // NOLINT(*-explicit-constructor)
{
create<Tp>(std::forward<ValueType>(value));
}
Expand Down

0 comments on commit fb88cf3

Please sign in to comment.