名前空間
変種
操作

Arithmetic operators

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
特定の算術演算の結果を返します。.
Original:
Returns the result of specific arithmetic operation.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operator name Syntax Over​load​able Prototype examples (for class T)
Inside class definition Outside class definition
unary plus +a Yes T T::operator+() const; T operator+(const T &a);
unary minus -a Yes T T::operator-() const; T operator-(const T &a);
addition a + b Yes T T::operator+(const T2 &b) const; T operator+(const T &a, const T2 &b);
subtraction a - b Yes T T::operator-(const T2 &b) const; T operator-(const T &a, const T2 &b);
multiplication a * b Yes T T::operator*(const T2 &b) const; T operator*(const T &a, const T2 &b);
division a / b Yes T T::operator/(const T2 &b) const; T operator/(const T &a, const T2 &b);
modulo a % b Yes T T::operator%(const T2 &b) const; T operator%(const T &a, const T2 &b);
bitwise NOT ~a Yes T T::operator~() const; T operator~(const T &a);
bitwise AND a & b Yes T T::operator&(const T2 &b) const; T operator&(const T &a, const T2 &b);
bitwise OR a | b Yes T T::operator|(const T2 &b) const; T operator|(const T &a, const T2 &b);
bitwise XOR a ^ b Yes T T::operator^(const T2 &b) const; T operator^(const T &a, const T2 &b);
bitwise left shift a << b Yes T T::operator<<(const T2 &b) const; T operator<<(const T &a, const T2 &b);
bitwise right shift a >> b Yes T T::operator>>(const T2 &b) const; T operator>>(const T &a, const T2 &b);
'注意'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • すべての組み込み演算子の戻り値、およびほとんどのユーザ定義のオーバーロードは、ユーザー定義演算子は組み込みと同様に使用できるようにして値を返すただし、ユーザー定義演算子のオーバーロードでは、任意の型、戻り値の型(voidを含む)として使用することができます。特に、ストリーム挿入とoperator<<のストリーム抽出オーバーロードとoperator>>リターンT&.
    Original:
    All built-in operators return values, and most user-defined overloads also return values so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (including void). In particular, stream insertion and stream extraction overloads of operator<< and operator>> return T&.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • T2T含む任意の型を指定できます
    Original:
    T2 can be any type including T
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 説明

すべての算術演算子は、特定の算術演算の結果を計算し、その結果を返します。引数は変更されません.
Original:
All arithmetic operators compute the result of specific arithmetic operation and returns its result. The arguments are not modified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 変換

算術演算子に渡されたオペランドが整数またはスコープを持たない列挙型である場合は、他のアクションの前に(ただし、左辺値から右辺値に変換した後、該当する場合)、オペランドは整数の昇格を受ける。オペランドが配列または関数型を持つ場合、配列からポインタと関数へのポインタ変換が適用されます.
Original:
If the operand passed to an arithmetic operator is integral or unscoped enumeration type, then before any other action (but after lvalue-to-rvalue conversion, if applicable), the operand undergoes 整数の昇格. If an operand has array or function type, array-to-pointer and function-to-pointer conversions are applied.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
二項演算子(シフトを除く)、昇格オペランドが異なる型を持つ場合、暗黙的な変換の追加セットは次のように通常の算術変換が知られて、適用される経由でもアクセス可能な一般的なタイプ'を(生成することを目的とするためのstd::common_type型形質)
Original:
For the binary operators (except shifts), if the promoted operands have different types, additional set of implicit conversions is applied, known as usual arithmetic conversions with the goal to produce the common type (also accessible via the std::common_type type trait)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • いずれかのオペランドがスコープの列挙型を持っている場合、変換は実行されません:もう一方のオペランドと戻り値の型が同じタイプである必要があります
    Original:
    If either operand has scoped enumeration type, no conversion is performed: the other operand and the return type must have the same type
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • どちらかのオペランドがlong doubleある場合、もう一方のオペランドはlong doubleに変換されます
    Original:
    Otherwise, if either operand is long double, the other operand is converted to long double
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • どちらかのオペランドがdoubleある場合、もう一方のオペランドはdoubleに変換されます
    Original:
    Otherwise, if either operand is double, the other operand is converted to double
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • どちらかのオペランドがfloatある場合、もう一方のオペランドはfloatに変換されます
    Original:
    Otherwise, if either operand is float, the other operand is converted to float
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • それ以外の場合は、オペランドは整数型を持つ(ブール型、char型、char16_t、char32_t、wchar_t型、およびスコープを持たない列挙は、この時点で促進されたため)、整数変換は、以下のように、一般的なタイプを生成するために適用されます
    Original:
    Otherwise, the operand has integer type (because bool, char, char16_t, char32_t, wchar_t, and unscoped enumeration were promoted at this point) and 整数変換 are applied to produce the common type, as follows:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 両方のオペランドが署名、またはその両方に署名がされている場合は、低いとオペランド変換ランクは大きい整数変換ランクのオペランドに変換されます
    Original:
    If both operands are signed or both are unsigned, the operand with lesser conversion rank is converted to the operand with the greater integer conversion rank
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 符号なしオペランドの変換ランクが大きいか、または符号付きオペランドの変換ランクと等しい場合はそうでない場合は、符号付きオペランドは符号なしオペランドの型に変換されます。.
    Original:
    Otherwise, if the unsigned operand's conversion rank is greater or equal to the conversion rank of the signed operand, the signed operand is converted to the unsigned operand's type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 符号付きオペランドの型が符号なしオペランドのすべての値を表すことができればそれ以外の場合は、符号なしオペランドは、署名者のオペランドの型に変換されます
    Original:
    Otherwise, if the signed operand's type can represent all values of the unsigned operand, the unsigned operand is converted to the signer operand's type
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • それ以外の場合は、両方のオペランドは符号付きオペランドの型の符号なしの相手に変換されます.
    Original:
    Otherwise, both operands are converted to the unsigned counterpart of the signed operand's type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
変換ランク順序で上記の増加boolsigned charshortintlonglong long。任意の符号なしの型のランクは、対応する符号付き型のランクに等しくなります。 charのランクはsigned charunsigned charのランクに等しくなります。 char16_tの仲間入り、char32_twchar_tとその基礎となる種類のランクに等しい.
Original:
The conversion rank above increases in order bool, signed char, short, int, long, long long. The rank of any unsigned type is equal to the rank of the corresponding signed type. The rank of char is equal to the rank of signed char and unsigned char. The ranks of char16_t, char32_t, and wchar_t are equal to the ranks of their underlying types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] オーバーフローします

nは、その特定の整数のビット数である符号なし整数演算は常にmodulo 2n
実行されます。例えばunsigned intため、UINT_MAXに1を加算する0を与え、0から1を引くとUINT_MAX与える.
Original:
Unsigned integer arithmetic is always performed modulo 2n
where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
整数演算がオーバーフローした(結果は結果の型に収まらない)に署名した場合、動作は未定義である:それは表現(典型的には2の補数)の規則に従って包み込むしれないが、それはいくつかのプラットフォームやコンパイラのためにトラップすることができオプション(例えば-ftrapvGCCとClangの)、または完全にoptimized out by the compilerかもしれません.
Original:
When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 単項算術演算子

すべての昇格算術型Aため、すべてのタイプのTため、次の関数のシグネチャは、オーバーロードの解決に関与します
Original:
For every promoted arithmetic type A and for every type T, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
A operator+(A)
T* operator+(T*)
A operator-(A)
組み込み単項プラス演算子は、オペランドの値を返します。オペランドは整数型または整数の昇格によって変更されたスコープを持たない列挙型を持っていたときにそれがno-opではない唯一の状況では、例えば、それはcharint変換またはオペランドが左辺値から右辺値の対象となっている場合、配列からポインタ、または関数へのポインタ変換.
Original:
The builtin unary plus operator returns the value of its operand. The only situation where it is not a no-op is when the operand has integral type or unscoped enumeration type, which is changed by integral promotion, e.g, it converts char to int or if the operand is subject to lvalue-to-rvalue, array-to-pointer, or function-to-pointer conversion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
組み込み単項マイナス演算子は、オペランドの負の値を計算します。符号なしaは、-aの値は2b
-a
が昇進後のビット数である場合、bです.
Original:
The builtin unary minus operator calculates the negative of its operand. For unsigned a, the value of -a is 2b
-a
, where b is the number of bits after promotion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 0x6a;
    int n1 = 1;
    unsigned char n2 = 1;
    unsigned int n3 = 1;
    std::cout << "char: " << c << " int: " << +c << '\n'
              << "-1, where 1 is signed: " << -n1 << '\n'
              << "-1, where 1 is unsigned char: " << -n2 << '\n'
              << "-1, where 1 is unsigned int: " << -n3 << '\n';
    char a[3];
    std::cout << "size of array: " << sizeof a << '\n'
              << "size of pointer: " << sizeof +a << '\n';
}

Output:

char: j int: 106
-1, where 1 is signed: -1
-1, where 1 is unsigned char: -1
-1, where 1 is unsigned int: 4294967295
size of array: 3
size of pointer: 8

[編集] 加算演算子

昇格算術型のペアごとLRし、各オブジェクト型のTため、次の関数のシグネチャは、オーバーロードの解決に関与します
Original:
For every pair of promoted arithmetic types L and R and for every object type T, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
LR operator+(L, R)
LR operator-(L, R)
T* operator+(T*, std::ptrdiff_t)
T* operator+(std::ptrdiff_t, T*)
T* operator-(T*, std::ptrdiff_t)
std::ptrdiff_t operator-(T*, T*)
LRLR上の通常の算術変換の結果です
Original:
where LR is the result of usual arithmetic conversions on L and R
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
算術演算子または列挙型のオペランドによる、バイナリの結果プラスオペランド(通常の算術converesions後)、バイナリマイナス演算子の結果の和であるから第二オペランドを減算した結果である(通常の算術変換した後).
Original:
With operands of arithmetic or enumeration type, the result of binary plus is the sum of the operands (after usual arithmetic converesions), and the result of the binary minus operator is the result of subtracting the second operand from the first (after usual arithmetic conversions).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
いずれかのオペランドがポインタである場合、次の規則が適用されます
Original:
If any of the operands is a pointer, the following rules apply:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 非配列オブジェクトへのポインタは、サイズが1の配列の最初の要素へのポインタとして扱われます。.
    Original:
    A pointer to non-array object is treated as a pointer to the first element of an array with size 1.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 場合は、配列の要素へのポインタPthのiポイント、その後の式P+nn+P、そしてP-ni+nth、i+nth、同じ配列の要素へのi-nth同じタイプその点、それぞれのポインタです。ポインタの加算の結果はまた、1 - 過去·ツー·エンドのポインタ(つまり、配列の最後の要素にPような発現P-1ポイントそのポインタ)とすることができる。他の状況では(つまり、同じ配列の要素を指していないポインタまたは末尾過去1を生成しようとする)は、未定義の動作を呼び出す.
    Original:
    If the pointer P points to the ith element of an array, then the expressions P+n, n+P, and P-n are pointers of the same type that point to the i+nth, i+nth, and i-nth element of the same array, respectively. The result of pointer addition may also be a one-past-the-end pointer (that is, pointer P such that the expression P-1 points to the last element of the array). Any other situations (that is, attempts to generate a pointer that isn't pointing at an element of the same array or one past the end) invoke undefined behavior.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同じ配列のPth要素で配列の要素へのポインタithのQポイント、およびポインタj指している場合は値がP-Qに収まれば、式i-jは、値std::ptrdiff_tを持っています。両方のオペランドが同じ配列(またはエンド過去の1)の要素を指している必要があり、そうでない場合の動作は未定義である。結果はstd::ptrdiff_tに収まらない場合、動作は未定義です.
    Original:
    If the pointer P points to the ith element of an array, and the pointer Q points at the jth element of the same array, the expression P-Q has the value i-j, if the value fits in std::ptrdiff_t. Both operands must point to the elements of the same array (or one past the end), otherwise the behavior is undefined. If the result does not fit in std::ptrdiff_t, the behavior is undefined.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 0が追加またはポインタから減算された場合、結果は変わらず、ポインタである。 2つのポインタが同じオブジェクトを指していたり​​、同じ配列の終わりを超えていずれか、または両方がNULLポインタである両方ある場合は、減算の結果は(std::ptrdiff_t)0に等しいです.
    Original:
    If the value 0 is added or subtracted from a pointer, the result is the pointer, unchanged. If two pointers point at the same object or are both one past the end of the same array, or both are null pointers, then the result of subtraction is equal to (std::ptrdiff_t)0.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
これらのポインタの算術演算子は、ポインタがRandomAccessIteratorコンセプトを満足することができます.
Original:
These pointer arithmetic operators allow pointers to satisfy the RandomAccessIterator concept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 2;
    unsigned int un = 2;
    int  n = -10;
    std::cout <<  " 2 + (-10), where 2 is a char    = " << c + n << '\n'
              <<  " 2 + (-10), where 2 is unsigned  = " << un + n << '\n'
              <<  " -10 - 2.12  = " << n - 2.12 << '\n';
 
    char a[4] = {'a', 'b', 'c', 'd'};
    char* p = &a[1];
    std::cout << "Pointer addition examples: " << *p << *(p + 2)
              << *(2 + p) << *(p - 1) << '\n';
    char* p2 = &a[4];
    std::cout << "Pointer difference: " << p2 - p << '\n';
}

Output:

2 + (-10), where 2 is a char    = -8
 2 + (-10), where 2 is unsigned  = 4294967288
 -10 - 2.12  = -12.12
Pointer addition examples: bdda
Pointer difference: 3

[編集] 乗算演算子

昇格算術型のペアごとLARAと昇格整数型のペアごとLIRI次の関数のシグネチャは、オーバーロードの解決に関与します
Original:
For every pair of promoted arithmetic types LA and RA and for every pair of promoted integral types LI and RI the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
LRA operator*(LA, RA)
LRA operator/(LA, RA)
LRI operator%(LI, RI)
LRxLxRx上の通常の算術変換の結果です
Original:
where LRx is the result of usual arithmetic conversions on Lx and Rx
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
二項演算子*は、オペランドの乗算を(通常の算術変換後)を行う.
Original:
The binary operator * performs multiplication of its operands (after usual arithmetic conversions).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
二項演算/秒で最初のオペランドを(通常の算術変換後)に分割します。番目のオペランドがゼロである場合、動作は未定義です。整数オペランドのために、それは代数商が得られます
Original:
The binary operator / divides the first operand by the second (after usual arithmetic conversions).If the second operand is zero, the behavior is undefined. For integral operands, it yields the algebraic quotient
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 実装定義の方向(C + + 11時まで)に丸められます
    Original:
    rounded in implementation-defined direction (C + + 11時まで)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 破棄された小数部(ゼロに向かって切り捨て)(C + + 11以来)
    Original:
    with any fractional part discarded (truncated towards zero) (C + + 11以来)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
二項演算子%は、秒単位で最初のオペランド(通常の算術変換後)の割り算の余りをもたらします。商a/bは結果の型にrepresentibleある場合、(a/b)*b + a%b == a。番目のオペランドがゼロである場合、動作は未定義です.
Original:
The binary operator % yields the remainder of the division of the first operand by the second (after usual arithmetic conversions). If the quotient a/b is representible in the result type, (a/b)*b + a%b == a. If the second operand is zero, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 一方または両方のオペランドが負の場合、それは整数の除算(C + + 11時まで)の丸め方向に依存して、余りの符号は、実装定義である
    Original:
    if one or both operands are negative, the sign of the remainder is implementation-defined, as it depends on the rounding direction of integer division (C + + 11時まで)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 2;
    unsigned int un = 2;
    int  n = -10;
    std::cout <<  "2 * (-10), where 2 is a char    = " << c * n << '\n'
              <<  "2 * (-10), where 2 is unsigned  = " << un * n << '\n'
              <<  "-10 / 2.12  = " << n / 2.12 << '\n'
              <<  "-10 / 21  = " << n / 21 << '\n'
              <<  "-10 % 21  = " << n % 21 << '\n';
}

Output:

2 * (-10), where 2 is a char    = -20
2 * (-10), where 2 is unsigned  = 4294967276
-10 / 2.12  = -4.71698
-10 / 21  = 0
-10 % 21  = -10

[編集] ビット単位の論理演算子

昇格整数型のペアごとLR次の関数のシグネチャは、オーバーロードの解決に関与します
Original:
For every pair of promoted integral types L and R the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
R operator~(R)
LR operator&(L, R)
LR operator^(L, R)
LR operator|(L, R)
LRLR上の通常の算術変換の結果です
Original:
where LR is the result of usual arithmetic conversions on L and R
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
演算子の結果は〜引数のビット単位のNOT(1の補数)の値(昇格後)です。演算子の結果はオペランドと(通常の算術変換後)のビット単位のAND値です。演算子の結果は
Original:
オペランド(通常の算術変換後)のビット単位の論理和(OR)の値です。演算子^の結果はオペランドのビット単位のXOR値(通常の算術変換後)になります
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    std::cout << std::hex << std::showbase;
    uint16_t mask = 0x00f0;
    uint32_t a = 0x12345678;
    std::cout << "Value: " << a << " mask: " << mask << '\n'
              << "Setting bits: " << (a

Output:

Value: 0x12345678 mask: 0xf0
Setting bits: 0x123456f8
Clearing bits: 0x12345608
Selecting bits: 0x70

[編集] ビットシフト演算子

昇格整数型のペアごとLR、次の関数のシグネチャは、オーバーロードの解決に関与します
Original:
For every pair of promoted integral types L and R, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
L operator<<(L, R)
L operator>>(L, R)
内蔵のビットシフト演算子のオペランドは整数型またはスコープを持たない列挙型のいずれかを持っている。汎整数拡張が評価する前に、両方のオペランドで実行されます。戻り値の型はintegalプロモーション後の左オペランドの型である.
Original:
The operands of the built-in bitwise shift operators have either integral types or unscoped enumeration type. Integral promotions are performed on both operands before evaluation. The return type is the type of the left operand after integal promotions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
符号なしaは、a << bの値がa * 2b
の値であり、戻り値の型プラス1(ビット単位の左シフトが実行されると、変換先の型の外にずれてビットが破棄されるということです)のモジュロ最大値を減少させた。それは戻り値の型で表現可能であれば署名aは、a << bの値がa * 2b
、それ以外の動作は未定義になります。.
Original:
For unsigned a, the value of a << b is the value of a * 2b
, reduced modulo maximum value of the return type plus 1 (that is, bitwise left shift is performed and the bits that get shifted out of the destination type are discarded). For signed a, the value of a << b is a * 2b
if it is representable by the return type, otherwise the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
符号なしaため、非負の値を持つ符号付きaため、a >> bの値はa/2b
の整数部分です。負aは、a >> bの値が(ほとんどの実装で、これは結果が負のままであるように、算術右シフトを実行します)実装定義である
Original:
For unsigned a and for signed a with nonnegative values, the value of a >> b is the integer part of a/2b
. For negative a, the value of a >> b is implementation-defined (in most implementations, this performs arithmetic right shift, so that the result remains negative)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
右のオペランドの値が負である以上または昇格左オペランドのビット数と等しい場合はどのような場合でも、動作は未定義です.
Original:
In any case, if the value of the right operand is negative or is greater or equal to the number of bits in the promoted left operand, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
enum {ONE=1, TWO=2};
int main()
{
    std::cout << std::hex << std::showbase;
    char c = 0x10;
    unsigned long long ull = 0x123;
    std::cout << "0x123 << 1 = " << (ull << 1) << '\n'
              << "0x123 << 63 = " << (ull << 63) << '\n' // overflow in unsigned
              << "0x10 << 10 = " << (c << 10) << '\n';   // char is promoted to int
    long long ll = -1000;
    std::cout << std::dec << "-1000 >> 1 = " << (ll >> ONE) << '\n';
}

Output:

0x123 << 1 = 0x246
0x123 << 63 = 0x8000000000000000
0x10 << 10 = 0x4000
-1000 >> 1 = -500

[編集] 標準ライブラリ

算術演算子は、多くの標準的なライブラリー·タイプのオーバーロードされています.
Original:
Arithmetic operators are overloaded for many standard library types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 単項算術演算子

単項+と単項を実装しています - 。。。
Original:
implements unary + and unary -
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::chrono::duration) [edit]
複素数に単項演算子を適用します
Original:
applies unary operators to complex numbers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
valarrayの各要素に単項算術演算子が適用されます
Original:
applies a unary arithmetic operator to each element of the valarray
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::valarray) [edit]

[編集] 加算演算子

与えられた期間で時刻を修正します
Original:
modifies the time point by the given duration
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
2つの文字列を連結または文字列とchar
Original:
concatenates two strings or a string and a char
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
進歩イテレータ
Original:
advances the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::reverse_iterator)
デクリメントイテレータ
Original:
decrements the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::reverse_iterator)
進歩イテレータ
Original:
advances the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::move_iterator)
デクリメントイテレータ
Original:
decrements the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::move_iterator)
2複雑な値や複雑とスカラーで複素数演算を実行します
Original:
performs complex number arithmetics on two complex values or a complex and a scalar
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
2 valarrays、またはのvalarrayと値の各要素に二項演算子を適用します
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]

[編集] 乗算演算子

引数として期間との間で演算を実装しています
Original:
implements arithmetic operations with durations as arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
2複雑な値や複雑とスカラーで複素数演算を実行します
Original:
performs complex number arithmetics on two complex values or a complex and a scalar
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
2 valarrays、またはのvalarrayと値の各要素に二項演算子を適用します
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]

[編集] ビット単位の論理演算子

バイナリのAND、OR、XORとNOTを実行します
Original:
performs binary AND, OR, XOR and NOT
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::bitset) [edit]
ビット集合上の2値論理演算を実行する
Original:
performs binary logic operations on bitsets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(機能) [edit]
valarrayの各要素に単項算術演算子が適用されます
Original:
applies a unary arithmetic operator to each element of the valarray
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::valarray)
2 valarrays、またはのvalarrayと値の各要素に二項演算子を適用します
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)

[編集] ビットシフト演算子

2 valarrays、またはのvalarrayと値の各要素に二項演算子を適用します
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)
右バイナリシフトと左シフトを実行します
Original:
performs binary shift left and shift right
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::bitset)

[編集] ストリーム挿入/抽出演算子

標準ライブラリを通して、ビットシフト演算子は、一般的に、左側のオペランドと戻り値の型の両方のI / Oストリーム(std::ios_base&またはそれから派生したクラスのいずれか)でオーバーロードされています。このような演算子はストリーム挿入として知られているストリーム抽出演算子:
Original:
Throughout the standard library, bitwise shift operators are commonly overloaded with I/O stream (std::ios_base& or one of the classes derived from it) as both the left operand and return type. Such operators are known as stream insertion and stream extraction operators:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
抽出は、データをフォーマットします
Original:
extracts formatted data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::basic_istream) [edit]
文字と文字配列を抽出します
Original:
extracts characters and character arrays
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
挿入してデータをフォーマットします
Original:
inserts formatted data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(パブリックメンバ関数of std::basic_ostream) [edit]
挿入文字データを
Original:
inserts character data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(機能) [edit]
複素数をシリアライズしてデシリアライズします
Original:
serializes and deserializes a complex number
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
ビット集合のストリームの入力と出力を行います
Original:
performs stream input and output of bitsets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(機能) [edit]
文字列上のストリームI / Oを実行します
Original:
performs stream I/O on strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
擬似乱数エンジンにストリーム入出力を行います
Original:
performs stream input and output on pseudo-random number engine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(機能) [edit]
擬似乱数分布にストリーム入出力を行います
Original:
performs stream input and output on pseudo-random number distribution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(機能) [edit]

[編集] も参照してください

演算子の優先順位

Common operators
代入 incrementNJdecrement 算術 論理 比較 memberNJaccess 他の

a = b
a = rvalue
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->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
? :

Special operators
static_cast別の互換性のあるタイプ
に1型に変換します
Original:
static_cast converts one type to another compatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dynamic_cast派生class
に仮想基底クラスに変換します
Original:
dynamic_cast converts virtual base class to derived class
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
const_cast異なるcvqualifiers
と互換性のある型に型変換されます
Original:
const_cast converts type to compatible type with different cv qualifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reinterpret_cast互換性type
に型を変換します
Original:
reinterpret_cast converts type to incompatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
new割り当てmemory
Original:
new allocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
delete割り当て解除memory
Original:
delete deallocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sizeoftype
のサイズを照会します
Original:
sizeof queries the size of a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sizeof...パラメーターパック(C + + 11以来)
のサイズを照会します
Original:
sizeof... queries the size of a パラメーターパック (C + + 11以来)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typeidtype
の型情報を照会します
Original:
typeid queries the type information of a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
noexcept式が例外(C + + 11以来)
を投げることができるかどうかをチェックします
Original:
noexcept checks if an expression can throw an exception (C + + 11以来)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alignofタイプ(C + + 11以来)のクエリアラインメント要件を
Original:
alignof queries alignment requirements of a type (C + + 11以来)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.