Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
Workshop: Safe and Efficient C++ for Embedded Environments
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <typeindex> #include <utility> template <typename T> struct tag { using type = T; }; namespace impl { // Don't need an ADL dummy for adl_ViewBase since we // only ever call it from inside impl:: template <typename D, std::size_t I> struct BaseViewer { friend constexpr auto adl_ViewBase(BaseViewer); }; template <typename D, std::size_t I, typename B> struct BaseWriter { friend constexpr auto adl_ViewBase(BaseViewer<D, I>) {return tag<B>{};} }; template <typename D, typename Next, std::size_t I = 0> struct NumBases : std::integral_constant<std::size_t, I> {}; } // Dummy ADL target. // Needs to exist somewhere since SFINAE disables the 'active' definitions template <typename T> constexpr void adl_RegisterBases(void *) {} template <typename T> struct Base { template < typename D, std::enable_if_t<std::is_base_of_v<T, D>, std::nullptr_t> = nullptr, typename impl::BaseWriter<D, impl::NumBases<D, T>::value , T>::nonExistent = nullptr > friend constexpr void adl_RegisterBases(void *) {} }; //----------------------- //Sample object hierarchy for testing struct A : Base<A> {}; struct B : Base<B>, A {}; struct C : Base<C> {}; struct D : Base<D>, B, C {}; int main () { //ADL hint: by casting to (A *), we tell the compiler to check //scopes related to A for possible overloads of adl_RegisterBases //Without the cast, the compiler just immediately instantiates our //dummy without actually checking relevant templates. //Casting nullptr to (A*) provides the hint without constructing A adl_RegisterBases<A>((A *)nullptr); }
Insight:
Console: