Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/language/operator logical"

From cppreference.com
< cpp‎ | language
(Created page with "{{title|Logical operators}} {{cpp/language/sidebar}} Returns a boolean value. {| class="wikitable" style="font-size:85%;" |- ! rowspan="2" | Operator name ! rowspan="2" | Keywor...")
 
m (replaced || with {{!!}} in table)
Line 32: Line 32:
 
| {{tt|<nowiki>a || b</nowiki>}}
 
| {{tt|<nowiki>a || b</nowiki>}}
 
| {{yes}}
 
| {{yes}}
| {{cpp|bool T::operator||(const T2 &b) const;}}
+
| {{cpp|bool T::operator{{!!}} (const T2 &b) const;}}
| {{cpp|bool operator||(const T &a, const T2 &b);}}
+
| {{cpp|bool operator{{!!}} (const T &a, const T2 &b);}}
 
|-
 
|-
 
| colspan="6" |
 
| colspan="6" |
 
:'''Notes'''<br>
 
:'''Notes'''<br>
* The keyword-like forms (and,or,not) and the symbol-like forms (&&,||,!) have exactly the same meaning everywhere they can occur
+
* The keyword-like forms ({{cpp|and}},{{cpp|or}},{{cpp|not}}) and the symbol-like forms ({{cpp|&&}},{{cpp|{{!!}}}},{{cpp|!}}) have exactly the same meaning everywhere they can occur
 
* Operators {{cpp|and}} and {{cpp|not}} perform short-circuit evaluation when used with basic type but that is not true if overloaded ( as they behave as functions )
 
* Operators {{cpp|and}} and {{cpp|not}} perform short-circuit evaluation when used with basic type but that is not true if overloaded ( as they behave as functions )
 
|}
 
|}

Revision as of 03:10, 5 March 2012

Template:cpp/language/sidebar Returns a boolean value.

Operator name Keyword Syntax Over​load​able Prototype examples (for Template:cpp)
Inside class definition Outside class definition
negation Template:cpp !a Yes Template:cpp Template:cpp
AND Template:cpp a && b Yes Template:cpp Template:cpp
inclusive OR Template:cpp a || b Yes Template:cpp Template:cpp
Notes

See also

Operator precedence

Common operators
assignment increment
decrement
arithmetic logical comparison member
access
other

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b
a <=> b

a[...]
*a
&a
a->b
a.b
a->*b
a.*b

function call
a(...)
comma
a, b
conditional
a ? b : c
Special operators

static_cast converts one type to another related type
dynamic_cast converts within inheritance hierarchies
const_cast adds or removes cv-qualifiers
reinterpret_cast converts type to unrelated type
C-style cast converts one type to another by a mix of static_cast, const_cast, and reinterpret_cast
new creates objects with dynamic storage duration
delete destructs objects previously created by the new expression and releases obtained memory area
sizeof queries the size of a type
sizeof... queries the size of a parameter pack (since C++11)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (since C++11)
alignof queries alignment requirements of a type (since C++11)