
- 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_void template in C++
In this article we will be discussing the working, syntax and examples of std::is_void template in C++ STL.
is_void is a template which comes under the <type_traits> header file. This template is used to check whether the given type T is a void type or not.
What is a void type in C++?
In simple words void means “empty” or “nothing”. When we declare a function as void then it is assumed that this function will return nothing.
We also declare void pointers, which are supposed to left unspecified. However, they must be referenced to another variable of other type, before the pointer is dereferenced. They can point to any object irrespective of their type, hence very useful for the programmers.
Syntax
template <class T>is_void;
Parameters
The template can have only parameter of type T, and check whether T is a void type or not.
Return value
It returns a Boolean value, true if the given type is a void type, and false if the given type is not a void type.
Example
Input: is_void<void>::value; Output: True Input: is_void<int>::value; Output: False
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_void:"; cout << "\nvoid:" << is_void<void>::value; cout << "\nconst void:" << is_void<const void>::value; cout << "\nint:" << is_void<int>::value; cout << "\nchar:" << is_void<char>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_void: Void: true Const void: true Int: false Char: false
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_void:"; cout << "\nDouble:" << is_void<double>::value; cout << "\nFloat:" << is_void<float>::value; cout << "\nvolatile void:" << is_void<volatile void>::value; cout << "\nconst volatile void:" << is_void<const volatile void>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_void: Double: false Float: false Volatile void: true Cost volatile void: true
- Related Articles
- What is void pointer in C language?
- Compare the void agreement and a void contract
- What is 'void' Operator in JavaScript?
- void pointer in C
- 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_unsigned 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++
