Why does double negation change the value of C++ concept?

Here the concept D is the same as the concept C

They are not. Constraints (and concept-ids) are normalized when checked for satisfaction and broken down to atomic constraints.

[temp.names]

8 A concept-id is a simple-template-id where the template-name is
a concept-name. A concept-id is a prvalue of type bool, and does not
name a template specialization. A concept-id evaluates to true if the
concept’s normalized constraint-expression ([temp.constr.decl]) is
satisfied ([temp.constr.constr]) by the specified template arguments
and false otherwise.

And the || is regarded differently in C and D:

[temp.constr.normal]

2 The normal form of an expression E is a constraint that is defined
as follows:

  • The normal form of an expression ( E ) is the normal form of E.
  • The normal form of an expression E1 || E2 is the disjunction of the normal forms of E1 and E2.
  • The normal form of an expression E1 && E2 is the conjunction of the normal forms of E1 and E2.
  • The normal form of a concept-id C<A1, A2, ..., An> is the normal form of the constraint-expression of C, after substituting A1,
    A2, …, An for C‘s respective template parameters in the
    parameter mappings in each atomic constraint. If any such substitution
    results in an invalid type or expression, the program is ill-formed;
    no diagnostic is required.
  • The normal form of any other expression E is the atomic constraint whose expression is E and whose parameter mapping is the identity
    mapping.

For C the atomic constraints are T::a and T::b.
For D there is only one atomic constraint that is !!(T::a || T::b).

Substitution failure in an atomic constraint makes it not satisfied and evaluate to false. C<A> is a disjunction of one constraint that is satisified, and one that is not, so it’s true. D<A> is false since its one and only atomic constraint has a substitution failure.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)