User-defined literals (depuis C++11)
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| This section is incomplete |
C + 11 introduit la possibilité d'ajouter des suffixes personnalisés pour les littéraux afin de fournir des valeurs différentes .
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.
You can help to correct and verify the translation. Click here for instructions.
Suffixé littérale peut être surchargé d'une manière très similaire aux opérateurs .
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.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Syntaxe
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 }
|
|||||||||
[modifier] Explication
| return | - | Retourne la valeur
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 | - | Déclaration spécificateur de séquence, peuvent contenir des mots clés comme constexpr ou inline
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 | - | Un valables C + + identificateur, avec le préfixe trait de soulignement. Identificateurs sans soulignement est réservé pour une utilisation future
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 | - | Valeur littérale résultant d'une intégrale
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 | - | Valeur résultant d'une littérale à virgule flottante
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 | - | Valeur résultant de caractère littéral
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 chaîne terminée telles qu'elles sont interprétées par le compilateur, pour les littéraux entières et flottantes
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 | - | Tampon et la taille d'une chaîne littérale
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 | - | Corps de la fonction
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. |
[modifier] Exemples
// 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;
Résultat :
0x123ABC

