
On Mon, Nov 18, 2013 at 8:42 AM, Louis Dionne <ldionne.2@gmail.com> wrote:
Louis Dionne <ldionne.2 <at> gmail.com> writes:
template <typename ...T> void allow_expansion(T&&...);
template <typename ...T> struct or_ { static constexpr bool value = !noexcept( allow_expansion((T::value ? throw : 0)...) ); };
How embarrassing; my unit test was very poor and the above trick does not seem to work. However, the following was tested more rigorously and works (with similar performance improvements):
template <typename ...T> constexpr bool all_pointers(T*...) { return true; }
template <typename ...T> constexpr bool all_pointers(T...) { return false; }
template <typename ...T> struct or_ { static constexpr bool value = !all_pointers( ((typename std::conditional<T::value, int, void*>::type)0)... ); };
template <> struct or_<> { static constexpr bool value = false; };
It requires N instantiations of std::conditional, doesn't it? In that case is it actually faster than the naive recursive instantiation of or_?