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:
// C++ program to illustrate std::is_array template #include <bits/stdc++.h> #include <boost/type_traits/is_array.hpp> #include <boost/typeof/typeof.hpp> using namespace std;
// Main Program 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:
// C++ program to illustrate std::is_array template #include <bits/stdc++.h> #include <boost/type_traits/is_array.hpp> #include <boost/typeof/typeof.hpp> using namespace std;
// A Structure struct sturec {
int x, y;
float a, b;
long t[90];
}; // A Class class student {
private :
string name;
int roll_no;
public :
student(string name, int roll_no);
string studentName( int roll_no);
}; // Parameterized Constructor student::student(string name, int roll_no)
{ this ->name = name;
this ->roll_no = roll_no;
} // Function that return the name // of the student string student::studentName( int roll_no)
{ return this ->name;
} // Main Program 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" ;
// Instance of Class
student S( "GeeksforGeeks" , 11840520);
cout << "instance of a class: "
<< boost::is_array< decltype (S)>::value
<< "\n" ;
// Array of Class
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