Namespaces
Variants
Views
Actions

C++ keywords: and

From cppreference.com
< cpp‎ | keyword
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++20)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
decltype (C++11)
auto (C++11)
alignas (C++11)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Implicit conversions - Explicit conversions
static_cast - dynamic_cast
const_cast - reinterpret_cast
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static
Special member functions
Templates
Miscellaneous
 
 

[edit] Usage

[edit] Example

#include <iostream>
#include <string>
 
void truth_table_entry(bool const x, bool const y)
{
    const std::string s[] = {"false ", "true  ", "and ", " "};
    const std::string x_and_y = s[x] + s[2] + s[y];
    const std::string r = s[x and y] + s[3];
 
    if (x + y == 0) std::cout << "┌──────────────────┬─────────┐\n";
    if (x + y <= 2) std::cout << "│ " << x_and_y <<" │ "<<r<<" │\n";
    if (x + y == 2) std::cout << "└──────────────────┴─────────┘\n";
}
 
int main()
{
    truth_table_entry(false, false);
    truth_table_entry(false, true );
    truth_table_entry(true , false);
    truth_table_entry(true , true );
}

Output:

┌──────────────────┬─────────┐
│ false and false  │ false   │
│ false and true   │ false   │
│ true  and false  │ false   │
│ true  and true   │ true    │
└──────────────────┴─────────┘