Skip to content

Commit

Permalink
Rename m_value to _tanuki_value.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed May 21, 2024
1 parent 534c21f commit 427507b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions doc/simple_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ an implementation for the ``void foo() const`` function:
:lines: 5-12

The ``Holder`` template parameter is a class defined in the tanuki library which stores the
value we are type-erasing as the ``m_value`` data member. ``Holder`` derives from ``foo1_iface_impl``
and thus we can reach the ``m_value`` data member via the cast
value we are type-erasing as the ``_tanuki_value`` data member. ``Holder`` derives from ``foo1_iface_impl``
and thus we can reach the ``_tanuki_value`` data member via the cast
``static_cast<const Holder *>(this)`` leveraging the
`curiously recurring template pattern (CRTP) <https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern>`__.
In other words, this implementation of the ``void foo() const`` function will invoke
Expand Down Expand Up @@ -106,7 +106,7 @@ function (such as, e.g., an ``int``)? The compiler will loudly complain:
.. code-block:: console
simple_interface.cpp:34:23: error: request for member ‘foo’ in [...] which is of non-class type ‘const int’
34 | m_value.foo();
34 | _tanuki_value.foo();
This is of course not ideal, for at least a couple of reasons:

Expand Down
40 changes: 20 additions & 20 deletions include/tanuki/tanuki.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ concept iface_has_impl = requires() {
// are checked in the generic ctors of the wrap class.
template <typename T, typename IFace, wrap_semantics Sem>
struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holder<T, IFace, Sem>, T, Sem> {
TANUKI_NO_UNIQUE_ADDRESS T m_value;
TANUKI_NO_UNIQUE_ADDRESS T _tanuki_value;

// Make sure we don't end up accidentally copying/moving
// this class.
Expand Down Expand Up @@ -609,15 +609,15 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
explicit holder(U &&x) noexcept(
std::is_nothrow_constructible_v<T, U &&>
&& detail::nothrow_default_initializable<detail::impl_from_iface<IFace, holder<T, IFace, Sem>, T, Sem>>)
: m_value(std::forward<U>(x))
: _tanuki_value(std::forward<U>(x))
{
}
template <typename... U>
requires(sizeof...(U) != 1u)
explicit holder(U &&...x) noexcept(
std::is_nothrow_constructible_v<T, U &&...>
&& detail::nothrow_default_initializable<detail::impl_from_iface<IFace, holder<T, IFace, Sem>, T, Sem>>)
: m_value(std::forward<U>(x)...)
: _tanuki_value(std::forward<U>(x)...)
{
}

Expand All @@ -636,7 +636,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
}
[[nodiscard]] void *_tanuki_value_ptr() noexcept final
{
return std::addressof(m_value);
return std::addressof(_tanuki_value);
}

[[nodiscard]] bool _tanuki_value_is_reference() const noexcept final
Expand All @@ -654,7 +654,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
// there is a default-constructible interface implementation.
if constexpr (std::is_copy_constructible_v<T>) {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
return new holder(m_value);
return new holder(_tanuki_value);
}

// NOTE: we should never reach this point as we are using this function
Expand All @@ -666,7 +666,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
[[nodiscard]] std::shared_ptr<detail::value_iface<IFace, Sem>> _tanuki_shared_clone_holder() const final
{
if constexpr (std::is_copy_constructible_v<T>) {
return std::make_shared<holder>(m_value);
return std::make_shared<holder>(_tanuki_value);
} else {
// NOTE: this is the one case in which we might end up here at runtime. This function
// is used only in the implementation of the copy() function to force deep copy
Expand All @@ -687,7 +687,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
#endif

// NOLINTNEXTLINE(cppcoreguidelines-owning-memory,clang-analyzer-cplusplus.PlacementNew)
return ::new (ptr) holder(m_value);
return ::new (ptr) holder(_tanuki_value);
}

// NOTE: we should never reach this point as we are using this function
Expand All @@ -705,7 +705,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
#endif

// NOLINTNEXTLINE(cppcoreguidelines-owning-memory,clang-analyzer-cplusplus.PlacementNew)
return ::new (ptr) holder(std::move(m_value));
return ::new (ptr) holder(std::move(_tanuki_value));
}

// NOTE: we should never reach this point as we are using this function
Expand All @@ -716,7 +716,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde

// Copy/move assignment and swap primitives.

// Copy-assign m_value into the m_value of v_iface.
// Copy-assign _tanuki_value into the _tanuki_value of v_iface.
void _tanuki_copy_assign_value_to(detail::value_iface<IFace, Sem> *v_iface) const final
{
if constexpr (std::is_copy_assignable_v<T>) {
Expand All @@ -726,7 +726,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
// the same T, the conversion chain should boil down to T * -> void * -> T *, which
// does not require laundering.
assert(typeid(T) == v_iface->_tanuki_value_type_index());
*static_cast<T *>(v_iface->_tanuki_value_ptr()) = m_value;
*static_cast<T *>(v_iface->_tanuki_value_ptr()) = _tanuki_value;
return;
}

Expand All @@ -735,12 +735,12 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
// the creation of a copyable value semantics wrap from a non-copyable value.
detail::unreachable(); // LCOV_EXCL_LINE
}
// Move-assign m_value into the m_value of v_iface.
// Move-assign _tanuki_value into the _tanuki_value of v_iface.
void _tanuki_move_assign_value_to(detail::value_iface<IFace, Sem> *v_iface) && noexcept final
{
if constexpr (std::is_move_assignable_v<T>) {
assert(typeid(T) == v_iface->_tanuki_value_type_index());
*static_cast<T *>(v_iface->_tanuki_value_ptr()) = std::move(m_value);
*static_cast<T *>(v_iface->_tanuki_value_ptr()) = std::move(_tanuki_value);
return;
}

Expand All @@ -749,11 +749,11 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
// the creation of a movable value semantics wrap from a non-movable value.
detail::unreachable(); // LCOV_EXCL_LINE
}
// Copy-assign the object of type T assumed to be stored in ptr into m_value.
// Copy-assign the object of type T assumed to be stored in ptr into _tanuki_value.
void _tanuki_copy_assign_value_from(const void *ptr) final
{
if constexpr (std::is_copy_assignable_v<T>) {
m_value = *static_cast<const T *>(ptr);
_tanuki_value = *static_cast<const T *>(ptr);
return;
}

Expand All @@ -765,7 +765,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
void _tanuki_move_assign_value_from(void *ptr) noexcept final
{
if constexpr (std::is_move_assignable_v<T>) {
m_value = std::move(*static_cast<T *>(ptr));
_tanuki_value = std::move(*static_cast<T *>(ptr));
return;
}

Expand All @@ -774,14 +774,14 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
// the creation of a movable value semantics wrap from a non-movable value.
detail::unreachable(); // LCOV_EXCL_LINE
}
// Swap m_value with the m_value of v_iface.
// Swap _tanuki_value with the _tanuki_value of v_iface.
void _tanuki_swap_value(detail::value_iface<IFace, Sem> *v_iface) noexcept final
{
if constexpr (std::swappable<T>) {
assert(typeid(T) == v_iface->_tanuki_value_type_index());

using std::swap;
swap(m_value, *static_cast<T *>(v_iface->_tanuki_value_ptr()));
swap(_tanuki_value, *static_cast<T *>(v_iface->_tanuki_value_ptr()));

return;
}
Expand Down Expand Up @@ -809,7 +809,7 @@ struct TANUKI_VISIBLE holder final : public detail::impl_from_iface<IFace, holde
void serialize(Archive &ar, unsigned)
{
ar &boost::serialization::base_object<detail::value_iface<IFace, Sem>>(*this);
ar & m_value;
ar & _tanuki_value;
}

#endif
Expand Down Expand Up @@ -2028,7 +2028,7 @@ template <typename Holder, typename U>

using T = typename detail::holder_value<Holder>::type;

const auto &val = static_cast<const Holder *>(h)->m_value;
const auto &val = static_cast<const Holder *>(h)->_tanuki_value;

if constexpr (detail::is_reference_wrapper_v<T>) {
return val.get();
Expand All @@ -2045,7 +2045,7 @@ template <typename Holder, typename U>

using T = typename detail::holder_value<Holder>::type;

auto &val = static_cast<Holder *>(h)->m_value;
auto &val = static_cast<Holder *>(h)->_tanuki_value;

if constexpr (detail::is_reference_wrapper_v<T>) {
if constexpr (std::is_const_v<std::remove_reference_t<std::unwrap_reference_t<T>>>) {
Expand Down
2 changes: 1 addition & 1 deletion tutorial/simple_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct foo1_iface_impl : public Base {
void foo() const override
{
std::cout << "foo1_iface_impl calling foo()\n";
static_cast<const Holder *>(this)->m_value.foo();
static_cast<const Holder *>(this)->_tanuki_value.foo();
}
};

Expand Down

0 comments on commit 427507b

Please sign in to comment.