std::numeric_limits<T>::traps
The value of std::numeric_limits
# Declarations
static const bool traps;
(until C++11)
static constexpr bool traps;
(since C++11)
# Notes
On most platforms integer division by zero always traps, and std::numeric_limits
On most platforms, floating-point exceptions may be turned on and off at run time (e.g. feenableexcept() on Linux or _controlfp on Windows), in which case the value of std::numeric_limits
# Example
#include <iostream>
#include <limits>
int main()
{
std::cout << std::boolalpha
<< "bool: traps = " << std::numeric_limits<bool>::traps << '\n'
<< "char: traps = " << std::numeric_limits<char>::traps << '\n'
<< "char16_t: traps = " << std::numeric_limits<char16_t>::traps << '\n'
<< "long: traps = " << std::numeric_limits<long>::traps << '\n'
<< "float: traps = " << std::numeric_limits<float>::traps << '\n';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 497 | C++98 | it was unclear what is returned if trappingis enabled or disabled at runtime | returns the enable statusat the start of the program |