Namespaces
Variants
Actions

Talk:cpp/types/conjunction

From cppreference.com

[edit] Short cut Example?

In the text it is written:

The short-circuit instantiation differentiates conjunction from fold expressions: a fold expression like (... && Bs::value) instantiates every B in Bs, while std::conjunction_v<Bs...> stops instantiation once the value can be determined.

Can you add an example where this is shown (e.g. a code, that works with std::conjunction_v<Bs...> but fails with a fold expression?

--Helmut (talk) 22:05, 14 August 2021 (PDT)

Here's a crude example
#include <type_traits>
 
namespace conjunction
{
template<typename... Ts>
constexpr bool are_all_default_constructible_v(std::conjunction_v<std::is_default_constructible<Ts>...>);
}
 
namespace fold
{
template<typename... Ts>
constexpr bool are_all_default_constructible_v((std::is_default_constructible_v<Ts> && ...));
}
 
int main()
{
    void(conjunction::are_all_default_constructible_v<int, int[], struct S>);
    void(fold::are_all_default_constructible_v<int, int[], struct S>);
}
--Ybab321 (talk) 14:34, 31 October 2022 (PDT)