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
None
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <iostream> #include <vector> #include <bitset> #include <tuple> template <int N> struct Fib { static const int value = Fib<N - 1>::value + Fib<N - 2>::value ; }; template <> struct Fib <0> { static const int value = 0; }; template <> struct Fib <1> { static const int value = 1; }; template <int i> struct Int2Type {static const int value = i;}; template <class ... T> struct cons; template <class H , class ... T> struct cons<H, T...> { using Head = H; using Tail = cons<T...> ; const static auto value = H::value; }; template <> struct cons<>{}; template <template<int>class F, int K, int i > struct generate_impl { typedef cons<Int2Type<F<i>::value>, typename generate_impl<F, K, i + 1>::value> value ; }; template <template<int>class F, int K > struct generate_impl <F , K , K > { typedef cons<> value; }; template <template<int>class F, int K > struct generate { typedef typename generate_impl<F, K, 0>::value value ; }; template <class TL> void print () { std::cout << TL::value << '\n'; print<typename TL::Tail>(); } template <> void print<cons<>>() { } int main() { print<generate<Fib, 5>::value>(); return 0; }
Insight:
Console: