28 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 29 #error Folly.Poly requires gcc-5 or greater 34 #include <type_traits> 44 #if !defined(__cpp_inline_variables) 45 #define FOLLY_INLINE_CONSTEXPR constexpr 47 #define FOLLY_INLINE_CONSTEXPR inline constexpr 106 class Tfx = detail::MetaIdentity,
107 class Access = detail::PolyAccess>
108 using PolySelf = decltype(Access::template self_<Node, Tfx>());
118 #if !defined(__cpp_template_auto) 136 #define FOLLY_POLY_MEMBERS(...) \ 137 typename decltype(::folly::detail::deduceMembers( \ 138 __VA_ARGS__))::template Members<__VA_ARGS__> 158 #define FOLLY_POLY_MEMBER(SIG, MEM) \ 159 ::folly::detail::MemberDef< \ 160 ::folly::detail::Member<decltype(::folly::sig<SIG>(MEM)), MEM>>::value 165 template <
class... Ts>
169 #define FOLLY_POLY_MEMBER(SIG, MEM) ::folly::sig<SIG>(MEM) 170 #define FOLLY_POLY_MEMBERS(...) ::folly::PolyMembers<__VA_ARGS__> 172 template <
auto... Ps>
173 struct PolyMembers {};
196 template <
class... I>
200 template <
class Base>
235 template <std::size_t N,
typename This,
typename... As>
237 -> decltype(detail::PolyAccess::call<N>(
238 static_cast<This&&>(_this),
239 static_cast<As&&>(
as)...)) {
240 return detail::PolyAccess::call<N>(
241 static_cast<This&&
>(_this), static_cast<As&&>(
as)...);
245 template <std::size_t N,
class I,
class Tail,
typename... As>
247 using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>;
248 return detail::PolyAccess::call<N>(
249 static_cast<This&&
>(_this), static_cast<As&&>(as)...);
253 template <std::size_t N,
class I,
class Tail,
typename... As>
255 using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>;
256 return detail::PolyAccess::call<N>(
257 static_cast<This&
>(_this), static_cast<As&&>(as)...);
261 template <std::size_t N,
class I,
class Tail,
typename... As>
263 using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>;
264 return detail::PolyAccess::call<N>(
265 static_cast<This
const&
>(_this), static_cast<As&&>(as)...);
275 auto poly_call(Poly&& _this, As&&...
as) -> decltype(poly_call<N, I>(
276 static_cast<Poly&&>(_this).
get(),
277 static_cast<As&&>(
as)...)) {
278 return poly_call<N, I>(
279 static_cast<Poly&&
>(_this).
get(),
static_cast<As&&
>(
as)...);
284 template <std::size_t N,
class I,
typename... As>
285 [[noreturn]] detail::Bottom
poly_call(detail::ArchetypeBase
const&, As&&...) {
303 template <
class T,
class I>
304 detail::AddCvrefOf<T, I>&&
poly_cast(detail::PolyRoot<I>&& that) {
305 return detail::PolyAccess::cast<T>(
std::move(that));
309 template <
class T,
class I>
310 detail::AddCvrefOf<T, I>&
poly_cast(detail::PolyRoot<I>& that) {
311 return detail::PolyAccess::cast<T>(that);
315 template <
class T,
class I>
316 detail::AddCvrefOf<T, I>
const&
poly_cast(detail::PolyRoot<I>
const& that) {
317 return detail::PolyAccess::cast<T>(that);
322 template <
class T,
class I>
323 [[noreturn]] detail::AddCvrefOf<T, I>&&
poly_cast(detail::ArchetypeRoot<I>&&) {
328 template <
class T,
class I>
329 [[noreturn]] detail::AddCvrefOf<T, I>&
poly_cast(detail::ArchetypeRoot<I>&) {
334 template <
class T,
class I>
335 [[noreturn]] detail::AddCvrefOf<T, I>
const&
poly_cast(
336 detail::ArchetypeRoot<I>
const&) {
345 std::enable_if_t<detail::IsPoly<Poly>::value,
int> = 0>
347 -> decltype(poly_cast<T>(std::declval<Poly>().
get())) {
348 return poly_cast<
T>(
static_cast<Poly&&
>(that).
get());
364 [[noreturn]]
inline std::type_info
const&
poly_type(
365 detail::ArchetypeBase
const&)
noexcept {
384 return detail::State::eEmpty == detail::PolyAccess::vtable(that)->state_;
425 std::enable_if_t<detail::Not<std::is_reference<I>>
::value,
int> = 0>
433 std::enable_if_t<detail::Not<std::is_const<I>>
::value,
int> = 0>
446 [[noreturn]]
inline detail::ArchetypeBase
poly_move(
447 detail::ArchetypeBase
const&)
noexcept {
466 struct PolyVal : PolyImpl<I> {
471 using Copyable = std::is_copy_constructible<PolyImpl<I>>;
474 using PolyRoot<I>::vptr_;
476 PolyRoot<I>& _polyRoot_()
noexcept {
479 PolyRoot<I>
const& _polyRoot_()
const noexcept {
505 PolyVal(PolyOrNonesuch
const& that);
512 using PolyImpl<I>::PolyImpl;
559 struct PolyRef :
private PolyImpl<I> {
563 AddCvrefOf<PolyRoot<I>, I>& _polyRoot_()
const noexcept;
565 Data* _data_() noexcept {
568 Data const* _data_()
const noexcept {
572 static constexpr RefType refType()
noexcept;
575 template <
class That,
class I2>
584 PolyRef(PolyRef
const& that)
noexcept;
634 std::enable_if_t<ReferenceCompatible<I, I2, I2&&>::value,
int> = 0>
642 std::enable_if_t<ReferenceCompatible<I, I2, I2&>::value,
int> = 0>
650 std::enable_if_t<ReferenceCompatible<I, I2, I2 const&>::value,
int> = 0>
662 AddCvrefOf<PolyImpl<I>, I>&
get()
const noexcept;
667 AddCvrefOf<PolyImpl<I>, I>& operator*()
const noexcept {
674 auto operator-> ()
const noexcept {
1128 struct Poly final : detail::PolyValOrRef<I> {
1129 friend detail::PolyAccess;
1131 using detail::PolyValOrRef<I>::PolyValOrRef;
1132 using detail::PolyValOrRef<I>::operator=;
1164 template <
class Sig>
1171 #undef FOLLY_INLINE_CONSTEXPR std::type_info const & poly_type(detail::PolyRoot< I > const &that) noexcept
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
#define FOLLY_INLINE_CONSTEXPR
MetaApply< impl::If_< If_ >, Then, Else > If
FOLLY_ALWAYS_INLINE void assume_unreachable()
auto poly_call(This &&_this, As &&...as) -> decltype(detail::PolyAccess::call< N >(static_cast< This && >(_this), static_cast< As && >(as)...))
detail::TypeList< Ts... > PolyMembers
constexpr detail::Sig< Sig > const sig
AtomicCounter< T, DeterministicAtomic > Base
bool poly_empty(detail::PolyRoot< I > const &that) noexcept
static const char *const value
detail::AddCvrefOf< T, I > & poly_cast(detail::PolyRoot< I > &)
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
constexpr Poly< I > && poly_move(detail::PolyRoot< I > &that) noexcept
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
static constexpr uint64_t data[1]
decltype(Access::template self_< Node, Tfx >()) PolySelf