名前空間
変種
操作

User-defined literals (C++11およびそれ以降)

提供: 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.
ブールリテラル
nullptrを (C++11)
ユーザーが定義します (C++11)
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.
インラインアセンブリ
 
C + + 11は、異なる値を提供するために、リテラルにカスタム接尾辞を追加する機能が導入されました.
Original:
C++11 introduced the ability to add custom suffixes to literals in order to provide different values.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル接尾辞は、演算子と非常によく似た方法でオーバーロードすることができます.
Original:
Literal suffixed can be overloaded in a way very similar to operators.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 構文

return decl operator"" name ( unsigned long long n ) { body }
return decl operator"" name ( long double d ) { body }
return decl operator"" name ( char c ) { body }
return decl operator"" name ( const char* str, size_t sz ) { body }
return decl operator"" name ( const char* cstr ) { body }

[編集] 説明

return -
値を返します
Original:
Return value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decl -
宣言指定子のシーケンス、またはconstexprinlineなどのキーワードを含めることができます
Original:
Declaration specifier sequence, can contain keywords as constexpr or inline
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
name -
アンダースコアで始まる有効なC + +の識別子。下線なしの識別子は、将来の使用のために予約されています
Original:
A valid C++ identifier, prefixed with an underscore. Identifiers without underscore are reserved for future use
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
整数リテラルの結果として得られた値
Original:
Value resulting from an integral literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d -
浮動小数点リテラルの結果として得られた値
Original:
Value resulting from a floating-point literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
c -
リテラル文字から結果の値
Original:
Value resulting from a character literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cstr -
整数および浮動小数点リテラルのため、コンパイラによって解析されたNULLで終わる文字列
Original:
Null-terminated string as parsed by the compiler, for integer and floating point literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str/sz -
リテラル文字列からバッファとサイズ
Original:
Buffer and size from a string literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
body -
関数本体
Original:
Function body
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

// used as conversion
inline constexpr long double operator"" _deg ( long double deg )
{
    return deg*3.141592/180;
}
...
double x = 90.0_deg; // x = 1.570796


// used with custom type
struct mytype
{
    ...
    mytype ( unsigned long long );
};
mytype operator"" _mytype ( unsigned long long n )
{
    return mytype(n);
}
...
mytype x = 123_mytype;


// used for side-effects
void operator"" _print ( const char* str )
{
    std::cout << str;
}
...
0x123ABC_print;

Output:

0x123ABC