Home > database >  How to understand "well formed when treated as an unevaluated operand"
How to understand "well formed when treated as an unevaluated operand"

Time:04-16

As per the document, which says that[emphasis mine]:

template <class Fn, class... ArgTypes>
struct is_invocable; 

Determines whether Fn can be invoked with the arguments ArgTypes.... Formally, determines whether INVOKE(declval<Fn>(), declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, where INVOKE is the operation defined in Callable.

How to understand the statement in bold? What's "an unevaluated operand"?

Maybe, a simple example helps to fully understand this matter.

CodePudding user response:

How to understand the statement in bold? What's "an unevaluated operand"?

An unevaluated operand is an operand that is not evaluated.

Maybe, a simple example helps to fully understand this matter.

void g(auto) requires false;
void f(auto x) { g(x); }

static_assert(is_invocable_v<decltype(f<int>), int>);
f(0); // ill-formed

Considering the above example, since is_invocable is not evaluated, g(x) in f will not actually be invoked either, so the static_assert will pass.

Since f(0) is actually evaluated, which will fail because g(0) fails to satisfy the constraints.

  • Related