c++ - How to do the conditional variable initialization at compiler time? -
c++11 standard have std::conditional<> template type selection boolean condition @ compiler time. how same operation select init value variable initialization? similar type = (exp) ? first_value : second_value; . i use template: template<bool b, typename t> inline constexpr t&& conditional_initialize(t&& i1, t&& i2) { return b ? std::move(i1) : std::move(i2); } but can used pod types: int = conditional_initialize<true>(1, 2); . array initialization template compiled error. wrong compile example: int a[] = conditional_initialize<true>({1, 2}, {3,4,5}); error message: no matching function call 'conditional_initialize(<brace-enclosed initializer list>, <brace-enclosed initializer list>)'; who can me template? template<class t, std::size_t n, std::size_t m, bool b> std::array<t, b?n:m> conditional_array( std::array<t, n>&& lhs, std::array<t, m>&& rhs