How to use constexpr function template to re-write a very long switch-case efficiently?

Advertisements To easily re-write a big switch-case, I’m trying constexpr function template like this (it’s only a simplified version with just cout): #include <iostream> template<int T> constexpr void bigSwitchCase(const int idx) { if (T == 1 && T == idx) { std::cout << 1 <<std::endl; return; } if (T == idx) { std::cout << T… Read More How to use constexpr function template to re-write a very long switch-case efficiently?

call template function for each template parameter in constexpr std::array<size_t,3>

Advertisements Given a function print<size_t>(void) and a constexpr std::array<size_t,3> q={1,2,3}, I want a loop that calls print<qi> for each qi in q. My minimal example looks like this: #include<iostream> #include<array> template<size_t n> void print(){ std::cout << n << "\n"; } template< size_t N, const std::array<const size_t,N> q> constexpr void print_long(){ // // I) this is… Read More call template function for each template parameter in constexpr std::array<size_t,3>