FOLLY_FOR_EACH_THIS_OVERLOAD_IN_CLASS_BODY_DELEGATE
Synopsis
Declared in <folly/Utility.h>
#define FOLLY_FOR_EACH_THIS_OVERLOAD_IN_CLASS_BODY_DELEGATE(MEMBER, DELEGATE)
Description
Helper macro to add 4 delegated, qualifier‐overloaded methods to a class
Example:
template <typename T> class optional { public: bool has_value() const;
T& value() & { if (!has_value()) { throw std::bad_optional_access(); } return m_value; }
const T& value() const& { if (!has_value()) { throw std::bad_optional_access(); } return m_value; }
T&& value() && { if (!has_value()) { throw std::bad_optional_access(); } return std::move(m_value); }
const T&& value() const&& { if (!has_value()) { throw std::bad_optional_access(); } return std::move(m_value); } };
This is equivalent to
template <typename T> class optional { template <typename Self> decltype(auto) value_impl(Self&& self) { if (!self.has_value()) { throw std::bad_optional_access(); } return std::forward<Self>(self).m_value; } // ...
public: bool has_value() const;
FOLLY_FOR_EACH_THIS_OVERLOAD_IN_CLASS_BODY_DELEGATE(value, value_impl); };
Note: This can be migrated to C++23's deducing this: https://www.open‐std.org/jtc1/sc22/wg21/docs/papers/2021/p0847r7.html
Parameters
Name |
Description |
MEMBER |
Name of the member function to generate. |
DELEGATE |
Name of the static implementation to delegate to. |
Created with MrDocs