std::is_arithmetic
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>| definiert in Header <type_traits>
|
||
template< class T > struct is_arithmetic; |
(seit C++11) | |
If T is an arithmetic type (that is, an integral type or a floating-point type), provides the member constant value equal true. For any other type, value is false.
Inherited from std::integral_constant
Member constants
value [statisch] |
true wenn T is an arithmetic type , false anders Original: true if T is an arithmetic type , false otherwise The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public static Mitglied konstanten) |
Member functions
operator bool |
wandelt das Objekt bool, gibt value Original: converts the object to bool, returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) |
Member types
Type
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
Notes
Arithmetic types are the types for which the built-in arithmetischen Operatoren (+, -, *, /) are defined (possibly in combination with the usual arithmetic conversions)
Specializations of std::numeric_limits are provided for all arithmetic types.
Mögliche Implementierung
template< class T >
struct is_arithmetic : std::integral_constant<bool,
std::is_integral<T>::value ||
std::is_floating_point<T>::value> {};
|
Beispiel
#include <iostream>
#include <type_traits>
class A {};
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_arithmetic<A>::value << '\n';
std::cout << std::is_arithmetic<int>::value << '\n';
std::cout << std::is_arithmetic<int&>::value << '\n';
std::cout << std::is_arithmetic<int*>::value << '\n';
std::cout << std::is_arithmetic<float>::value << '\n';
std::cout << std::is_arithmetic<float&>::value << '\n';
std::cout << std::is_arithmetic<float*>::value << '\n';
}
Output:
false
true
false
false
true
false
false
