std::is_unsigned

Header: <type_traits>

std::is_unsigned is a UnaryTypeTrait.

# Declarations

template< class T >
struct is_unsigned;

(since C++11)

# Example

#include <iostream>
#include <type_traits>
 
class A {};
static_assert(std::is_unsigned_v<A> == false);
 
enum B : unsigned {};
static_assert(std::is_unsigned_v<B> == false);
 
enum class C : unsigned {};
static_assert(std::is_unsigned_v<C> == false);
 
struct S { unsigned p : 1; int q : 1; };
static_assert
(
    std::is_unsigned_v<decltype(S::p)> not_eq
    std::is_unsigned_v<decltype(S::q)>
);
 
static_assert
(
    std::is_unsigned_v<float> == false &&
    std::is_unsigned_v<signed int> == false &&
    std::is_unsigned_v<unsigned int> == true &&
    std::is_unsigned_v<bool> == true
);
 
int main() 
{
    // signedness of char is implementation-defined:
    std::cout << std::boolalpha << std::is_unsigned<char>::value << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2197C++11value could be true even if T is not an arithmetic typecan only be false in this case

# See also