Skip to content

Commit 263f931

Browse files
committed
[meta.logical] Add example of short-circuiting
1 parent 7b94925 commit 263f931

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/meta.tex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,23 @@
21942194
This is analogous to the short-circuiting behavior of
21952195
the built-in operator \tcode{\&\&}.
21962196
\end{note}
2197+
\begin{note}
2198+
This allows types without a \tcode{value} static data member
2199+
to be template arguments for \tcode{conjunction}, as long as an
2200+
earlier argument evaluates to \tcode{false}, for example:
2201+
\begin{codeblock}
2202+
template<class T>
2203+
concept HasValue = requires { { T::value } -> std::convertible_to<bool>; };
2204+
template<class T>
2205+
using maybe_value = std::conjunction<std::bool_constant<HasValue<T>>, T>;
2206+
2207+
struct X { };
2208+
2209+
static_assert( ! maybe_value<X>::value ); // OK, \tcode{X::value} not used
2210+
static_assert( ! maybe_value<int>::value ); // OK, \tcode{int::value} not used
2211+
static_assert( maybe_value<std::true_type>::value );
2212+
\end{codeblock}
2213+
\end{note}
21972214

21982215
\pnum
21992216
Every template type argument

0 commit comments

Comments
 (0)