如何理解"well formed when treated as an unevaluated operand"
How to understand "well formed when treated as an unevaluated operand"
根据 document,它说[强调我的]:
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.
void g(auto) requires false;
void f(auto x) { g(x); }
static_assert(is_invocable_v<decltype(f<int>), int>);
f(0); // ill-formed
考虑到上面的例子,由于is_invocable
没有计算,f
中的g(x)
实际上也不会被调用,所以static_assert
会通过。
由于f(0)
实际被求值,会因为g(0)
不满足约束条件而失败
根据 document,它说[强调我的]:
template <class Fn, class... ArgTypes> struct is_invocable;
Determines whether
Fn
can be invoked with the argumentsArgTypes....
Formally, determines whetherINVOKE(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.
void g(auto) requires false;
void f(auto x) { g(x); }
static_assert(is_invocable_v<decltype(f<int>), int>);
f(0); // ill-formed
考虑到上面的例子,由于is_invocable
没有计算,f
中的g(x)
实际上也不会被调用,所以static_assert
会通过。
由于f(0)
实际被求值,会因为g(0)
不满足约束条件而失败