
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
is_unsigned template in C++
In this article we will be discussing the working, syntax and examples of std::is_unsigned template in C++ STL.
is_unsigned is a template which comes under <type_traits> header file. This template is used to check whether the given type T is an unsigned type or not.
What are unsigned data types in C++?
Unsigned data types are those which we use knowing the values will not go in negative, like roll number, id of random numbers, etc.
To make a type as unsigned we use keyword unsigned as prefix of the data type like −
unsigned int;
unsigned float;
Syntax
template <class T>is_unsigned;
Parameters
The template can have only parameter of type T, and check whether T is an unsigned type or not.
Return value
It returns a Boolean value, true if the given type is an unsigned type, and false if the given type is not an unsigned type.
Example
Input: is_unsigned<unsigned int>::value; Output: True Input: is_unsigned<int>::value; Output: False
Example
#include <iostream> #include <type_traits> using namespace std; class TP { }; enum TP_1 : int {}; enum class TP_2 : int {}; int main() { cout << boolalpha; cout << "checking for is_unsigned:"; cout << "\nint:" << is_unsigned<int>::value; cout << "\nTP:" << is_unsigned<TP>::value; cout << "\nTP_1:" << is_unsigned<TP_1>::value; cout << "\nTP_2:" << is_unsigned<TP_2>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_unsigned: Int: false TP: false TP_1: false TP_2: false
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_unsigned:"; cout << "\nfloat:" << is_unsigned<float>::value; cout << "\nSigned int:" << is_unsigned<signed int>::value; cout << "\nUnsigned int:" << is_unsigned<unsigned int>::value; cout << "\ndouble:" << is_unsigned<double>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_signed: Float: false Signed int: false Unsigned int: true Double: false
- Related Articles
- What is unsigned in MySQL?
- What is an unsigned char in C++?
- What is unsigned Right Shift Operator (>>>) in JavaScript?
- Unsigned binary integers
- Template Metaprogramming in C++
- is_final template in C++
- is_fundamental Template in C++
- is_pod template in C++
- is_pointer Template in C++
- is_signed template in C++
- is_void template in C++
- is_standard_layout template in C++
- is_class template in C++
- is_const Template in C++
- is_lvalue_reference Template in C++
