#include // compiled with clang (tags/RELEASE_600/final) #include // or g++ (GCC) 7.3.1 20180406 -- from hare1039 namespace functional_list // basic building block for template meta programming { struct NIL { using head = NIL; using tail = NIL; friend std::ostream& operator << (std::ostream& os, NIL const) { return os; } }; template struct list { using head = H; using tail = T; }; template struct integer { static constexpr int value = i; friend std::ostream& operator << (std::ostream& os, integer const) { os << integer::value; return os;} }; template constexpr auto at() { if constexpr (nTH == 0) return (typename L::head){}; else if constexpr (not std::is_same_v) return at(); else return NIL{}; } template using at_t = decltype(at()); template constexpr auto prepend() { return list{}; } template using prepend_t = decltype(prepend()); template > constexpr auto gen_list() { if constexpr (Size == 0) return NIL{}; else { using next = decltype(gen_list()); return prepend(); } } template > using gen_list_t = decltype(gen_list()); } namespace fl = functional_list; constexpr int door_amount = 101; // index from 1 to 100 template constexpr auto construct_loop() { using val_t = fl::at_t; if constexpr (std::is_same_v) return fl::NIL{}; else { constexpr int val = val_t::value; using val_add_t = fl::integer; using val_old_t = fl::integer; if constexpr (current == door_amount) { if constexpr(current % moder == 0) return fl::list{}; else return fl::list{}; } else { using sub_list = decltype(construct_loop()); if constexpr(current % moder == 0) return fl::prepend(); else return fl::prepend(); } } } template constexpr auto construct() { if constexpr (iteration == 1) // door index = 1 { using l = fl::gen_list_t; return construct_loop(); } else { using prev_iter_list = decltype(construct()); return construct_loop(); } } template constexpr void show_ans() { if constexpr (std::is_same_v) return; else { if constexpr (L::head::value % 2 == 1) std::cout << "Door " << pos << " is opened.\n"; show_ans(); } } int main() { using result = decltype(construct<100>()); show_ans(); }