std::is_literal_type in C++ with Examples

The std::is_literal_type template of C++ STL is present in the <type_traits> header file. The std::is_literal_type template of C++ STL is used to check whether the T is literal type or not. It return the boolean value true if T is literal type, otherwise return false.

Header File:

#include<type_traits>

Template:

template< class T >
struct is_literal_type;

Syntax:

std::is_literal_type::value

Parameter: The template std::is_literal_type accepts a single parameter T(Trait class) to check whether T is literal type or not.



Return Value: The template std::is_literal_type returns a boolean variable as shown below:

  • True: If the type T is a literal type.
  • False: If the type T is not a literal type.

Below is the program to demonstrate std::is_literal_type: in C/C++:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// std::is_literal_type
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
  
// Declare Classes
class X {
};
  
class Y {
  
    // Destructor
    ~Y() {}
};
  
// Declare structures
struct A {
    int m;
};
  
struct B {
    virtual ~B();
};
  
// Driver Code
int main()
{
  
    cout << boolalpha;
  
    // Check if int is literal type?
    cout << "int: "
         << is_literal_type<int>::value
         << endl;
  
    // Check if class X is literal type?
    cout << "class X: "
         << is_literal_type<X>::value
         << endl;
  
    // Check if class Y is literal type?
    cout << "class Y: "
         << is_literal_type<Y>::value
         << endl;
  
    // Check if int* is literal type?
    cout << "int*: "
         << is_literal_type<int*>::value
         << endl;
  
    // Check if struct A is literal type?
    cout << "struct A: "
         << is_literal_type<A>::value
         << endl;
  
    // Check if struct B is literal type?
    cout << "struct B: "
         << is_literal_type<B>::value
         << endl;
  
    return 0;
}

chevron_right


Output:

int: true
class X: true
class Y: false
int*: true
struct A: true
struct B: false

Reference: http://www.cplusplus.com/reference/type_traits/is_literal_type/

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.