Skip to content
Open
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
53 changes: 24 additions & 29 deletions include/proxy/v4/detail/facade_meta_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,44 +140,18 @@ struct invoker;
PRO4D_DEF_OVERLOAD_SPECIALIZATIONS(PRO4D_DEF_INVOKER)
#undef PRO4D_DEF_INVOKER

template <class M>
struct PRO4D_ENFORCE_EBO inplace_meta_storage : M {
using M::M;

inplace_meta_storage() = default;
inplace_meta_storage(const inplace_meta_storage&) = default;
template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
inplace_meta_storage(const inplace_meta_storage<M2>& rhs) noexcept
: M(static_cast<const M&>(*rhs)) {}
inplace_meta_storage& operator=(const inplace_meta_storage&) = default;
template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
inplace_meta_storage&
operator=(const inplace_meta_storage<M2>& rhs) noexcept {
static_cast<M&>(*this) = static_cast<const M&>(*rhs);
return *this;
}

const M& operator*() const noexcept { return *this; }
};

template <class M>
struct static_meta_storage {
static_meta_storage() = default;
template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
static_meta_storage(const static_meta_storage<M2>& rhs) noexcept
: ptr_(std::addressof(static_cast<const M&>(*rhs))) {}
template <class P>
explicit static_meta_storage(std::in_place_type_t<P>)
: ptr_(std::addressof(storage<P>)) {}
template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
static_meta_storage& operator=(const static_meta_storage<M2>& rhs) noexcept {
ptr_ = std::addressof(static_cast<const M&>(*rhs));
return *this;
}
template <class P>
explicit static_meta_storage(std::in_place_type_t<P>)
: ptr_(std::addressof(storage<P>)) {}
bool has_value() const noexcept { return ptr_ != nullptr; }
void reset() noexcept { ptr_ = nullptr; }
const M& operator*() const noexcept { return *ptr_; }
Expand All @@ -189,6 +163,27 @@ struct static_meta_storage {
static inline const M storage{std::in_place_type<P>};
};

template <class M>
struct inplace_meta_storage : M {
using M::M;

template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
inplace_meta_storage&
operator=(const inplace_meta_storage<M2>& rhs) noexcept {
static_cast<M&>(*this) = *rhs;
return *this;
}
template <class M2>
requires(std::is_nothrow_convertible_v<const M2&, const M&>)
inplace_meta_storage& operator=(const static_meta_storage<M2>& rhs) noexcept {
static_cast<M&>(*this) = *rhs;
return *this;
}

const M& operator*() const noexcept { return *this; }
};

} // namespace detail

struct compact_facade_meta_traits {
Expand Down
26 changes: 26 additions & 0 deletions tests/proxy_lifetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,32 @@ TEST(ProxyLifetimeTests, Test_CopySubstitution_FromNull) {
ASSERT_FALSE(p2.has_value());
}

TEST(ProxyLifetimeTests, Test_CopySubstitution_MixedMetaStorage) {
struct Super : pro::facade_builder //
::add_convention<utils::spec::FreeToString,
std::string() const> //
::support_copy<pro::constraint_level::trivial> //
::support_relocation<pro::constraint_level::trivial> //
::support_destruction<pro::constraint_level::trivial> //
::build {};
struct Derived : pro::facade_builder //
::add_facade_with_substitution<Super> //
::build {};
static_assert(
pro::detail::specialization_of<pro::compact_facade_meta_traits::storage<
pro::detail::proxy_meta<Super>>,
pro::detail::inplace_meta_storage>);
static_assert(
pro::detail::specialization_of<pro::compact_facade_meta_traits::storage<
pro::detail::proxy_meta<Derived>>,
pro::detail::static_meta_storage>);
int v = 123;
pro::proxy<Derived> p1 = &v;
pro::proxy<Super> p2 = p1;
ASSERT_EQ(ToString(*p1), "123");
ASSERT_EQ(ToString(*p2), "123");
}

TEST(ProxyLifetimeTests, Test_MoveSubstitution_FromValue) {
utils::LifetimeTracker tracker;
std::vector<utils::LifetimeOperation> expected_ops;
Expand Down
Loading