Name

not operator — Logical negation operator

Synopsis

               unary-expr := ! cast-expr | not cast-expr
            

The not operator converts its operand to type bool, inverts its value, and returns a bool result. The not keyword is interchangeable with the ! token.

Example

template<typename C>
typename C::value_type checked_first(const C& c)
{
  if (not c.empty(  ))
    return c[0];
  throw std::out_of_range("container is empty");
}

See Also

and, bool, expression, or, Chapter 3, <ciso646>

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.