Skip to content

Commit

Permalink
Short-circuit all_of/any_of/none_of instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ballo committed Aug 8, 2017
1 parent c721a35 commit b472866
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions hpx/util/detail/pack.hpp
Expand Up @@ -70,9 +70,16 @@ namespace hpx { namespace util { namespace detail
>
{};

template <typename ...Ts>
static std::false_type _all_of(...);

template <typename ...Ts>
static auto _all_of(int) -> all_of<pack_c<bool,
typename std::enable_if<((bool)Ts::value), bool>::type(true)...>>;

template <typename ...Ts>
struct all_of
: all_of<pack_c<bool, ((bool)Ts::value)...> >
: decltype(detail::_all_of<Ts...>(0))
{};

template <>
Expand All @@ -86,13 +93,23 @@ namespace hpx { namespace util { namespace detail
template <bool ...Vs>
struct any_of<pack_c<bool, Vs...> >
: std::integral_constant<bool,
!all_of<pack_c<bool, !Vs...> >::value
!std::is_same<
pack_c<bool, Vs...>
, pack_c<bool, (Vs && false)...> // false...
>::value
>
{};

template <typename ...Ts>
static std::true_type _any_of(...);

template <typename ...Ts>
static auto _any_of(int) -> any_of<pack_c<bool,
typename std::enable_if<!((bool)Ts::value), bool>::type(false)...>>;

template <typename ...Ts>
struct any_of
: any_of<pack_c<bool, ((bool)Ts::value)...> >
: decltype(detail::_any_of<Ts...>(0))
{};

template <>
Expand All @@ -108,9 +125,16 @@ namespace hpx { namespace util { namespace detail
: all_of<pack_c<bool, !Vs...> >
{};

template <typename ...Ts>
static std::true_type _none_of(...);

template <typename ...Ts>
static auto _none_of(int) -> none_of<pack_c<bool,
typename std::enable_if<!((bool)Ts::value), bool>::type(true)...>>;

template <typename ...Ts>
struct none_of
: none_of<pack_c<bool, ((bool)Ts::value)...> >
: decltype(detail::_none_of<Ts...>(0))
{};

template <>
Expand Down

0 comments on commit b472866

Please sign in to comment.