Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Created January 21, 2022 15:19
Show Gist options
  • Save hjroh0315/05d37bbfa4bf50eb00e25a93576ae5d7 to your computer and use it in GitHub Desktop.
Save hjroh0315/05d37bbfa4bf50eb00e25a93576ae5d7 to your computer and use it in GitHub Desktop.
정신나간 컴파일타임 피보나치
#include<iostream>
template <int ... Ns> struct sequence {};
template <int ... Ns> struct seq_gen;
template <int I,int J, int ... Ns>
struct seq_gen<I,J, Ns...>
{
using type = typename seq_gen<
J-I,I,J, Ns...>::type;
};
template <int ... Ns>
struct seq_gen<1,1, Ns...>
{
using type = sequence<1,1,Ns...>;
};
template<int ... Ns>
void print(sequence<Ns...> seq)
{
(std::cout << Ns << " ",...);
std::cout<<std::endl;
}
template <int N,int O>
using sequence_t = typename seq_gen<N,O>::type;
using namespace std;
int main()
{
sequence_t<196418, 317811> seq;
print(seq);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment