std::numeric_limits::is_modulo
Da cppreference.com.
< cpp | types | numeric limits
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
staticconstbool is_modulo | (fino al c++11) | |
staticconstexprbool is_modulo | (dal C++11) | |
The value of std::numeric_limits<T>::is_modulo is true for all arithmetic types T
that handle overflows with modulo arithmetic, that is, if the result of addition, subtraction, multiplication, or division of this type would fall outside the range [min(), max()], the value returned by such operation differs from the expected value by a multiple of max()-min()+1.
[modifica]Specializzazioni standard
T | valore di std::numeric_limits<T>::is_modulo Original: value of std::numeric_limits<T>::is_modulo The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
/* non-specialized */ | false |
bool | false |
char | true |
signedchar | true |
unsignedchar | true |
wchar_t | true |
char16_t | true |
char32_t | true |
short | true |
unsignedshort | true |
int | true |
unsignedint | true |
long | true |
unsignedlong | true |
longlong | true |
unsignedlonglong | true |
float | false |
double | false |
longdouble | false |
[modifica]Esempio
Demonstrates the behavior of modulo types
#include <iostream>#include <type_traits>#include <limits> template<class T>typenamestd::enable_if<std::numeric_limits<T>::is_modulo>::type check_overflow(){std::cout<<"\nmax value is "<<std::numeric_limits<T>::max()<<'\n'<<"min value is "<<std::numeric_limits<T>::min()<<'\n'<<"max value + 1 is "<<std::numeric_limits<T>::max()+1<<'\n';} int main(){ check_overflow<int>(); check_overflow<unsignedlong>();// check_overflow<float>(); // compile-time error, not a modulo type}
Output:
max value is 2147483647 min value is -2147483648 max value + 1 is -2147483648 max value is 18446744073709551615 min value is 0 max value + 1 is 0
[modifica]Vedi anche
[statico] | identifica i tipi interi Original: identifies integer types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (pubblico membro statico costante) |
[statico] | individua le IEC 559/IEEE 754 tipi a virgola mobile Original: identifies the IEC 559/IEEE 754 floating-point types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (pubblico membro statico costante) |
[statico] | identifica i tipi esatti Original: identifies exact types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (pubblico membro statico costante) |