boost::type_traits::is_array Template in C++
Last Updated :
30 Mar, 2020
The std::boost::is_array template of Boost C++ Library used to check whether the given type is an array type or not. It returns a boolean value showing the same.
Header Files:
#include "boost/type_traits/is_array.hpp"
or
#include "boost/type_traits.hpp"
Template Class:
template <class T>
struct is_array : public true_type-or-false_type {};
If T is an array type then inherits from true_type else inherits from false_type.
Syntax:
boost::integral_constant ::value
boost::integral_constant ::value_type
boost::integral_constant ::type
Parameter: This template accepts a single parameter T(Trait class) to check whether T is a pointer type or not.
Accepted Arguments:
typename T
volatile T []
const volatile T []
const T []
T []
const volatile T[N]
volatile T [N]
const T [N]
T [N]
Return Value: This template returns a boolean value as shown below:
- True: If the type is a pointer value.
- False: If the type is a not pointer value.
Below programs illustrate the std::boost::type_traits::is_array template:
Program 1:
#include <bits/stdc++.h>
#include <boost/type_traits/is_array.hpp>
#include <boost/typeof/typeof.hpp>
using namespace std;
int main()
{
cout << "is_array: \n" ;
cout << "int[]: "
<< boost::is_array< int []>::value
<< "\n" ;
cout << "char[]: "
<< "boost::is_array<char[]>::value"
<< "\n" ;
cout << "double[20]: "
<< boost::is_array< double [20]>::value
<< "\n" ;
cout << "float[30]: "
<< boost::is_array< float [30]>::value
<< "\n" ;
cout << "bool[][6]: "
<< boost::is_array< bool [][6]>::value
<< "\n" ;
cout << "long[56][34][98]: "
<< boost::is_array< long [56][34][98]>::value
<< "\n" ;
bool a[98];
cout << "bool a[98]: "
<< boost::is_array< decltype (a)>::value
<< "\n" ;
char c[0];
cout << "char c[0]: "
<< boost::is_array< decltype (c)>::value
<< "\n" ;
return 0;
}
|
Output:
is_array:
int[]: 1
char[]: boost::is_array::value
double[20]: 1
float[30]: 1
bool[][6]: 1
long[56][34][98]: 1
bool a[98]: 1
char c[0]: 0
Program 2:
#include <bits/stdc++.h>
#include <boost/type_traits/is_array.hpp>
#include <boost/typeof/typeof.hpp>
using namespace std;
struct sturec {
int x, y;
float a, b;
long t[90];
};
class student {
private :
string name;
int roll_no;
public :
student(string name, int roll_no);
string studentName( int roll_no);
};
student::student(string name, int roll_no)
{
this ->name = name;
this ->roll_no = roll_no;
}
string student::studentName( int roll_no)
{
return this ->name;
}
int main()
{
cout << "is_array: \n" ;
sturec s;
sturec p[3];
cout << "instance of structure: "
<< boost::is_array< decltype (s)>::value
<< "\n" ;
cout << "array of structure: "
<< boost::is_array< decltype (p)>::value
<< "\n" ;
student S( "GeeksforGeeks" , 11840520);
cout << "instance of a class: "
<< boost::is_array< decltype (S)>::value
<< "\n" ;
student a[3] = {
{ "Abc Def" , 11840820 },
{ "Xyz Xyz" , 11840220 },
{ "ABcd Gfgh" , 11840950 }
};
cout << "array of a class: "
<< boost::is_array< decltype (a)>::value
<< "\n" ;
return 0;
}
|
Output:
is_array:
instance of structure: 0
array of structure: 1
instance of a class: 0
array of a class: 1
Share your thoughts in the comments
Please Login to comment...