Boost logo

Boost :

Subject: Re: [boost] Interesting variadic template trick
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2013-11-17 23:42:46

Louis Dionne <ldionne.2 <at>> 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;


Louis Dionne

Boost list run by bdawes at, gregod at, cpdaniel at, john at