📌  相关文章
📜  C++中的std :: is_constructible模板及其示例

📅  最后修改于: 2021-05-30 01:54:45             🧑  作者: Mango

< type_traits >头文件中提供了C++ STL的std :: is_constructible模板。 C++ STL的std :: is_constructible模板用于检查给定类型T是否是带有参数集的可构造类型。如果T是可构造类型type,则返回布尔值true,否则返回false。

头文件:

#include

模板类别:

template 
struct is_constructible;

句法:

std::is_constructible::value

参数:

  • T:代表数据类型。
  • Args:表示数据类型T的列表。

返回值:该模板返回一个布尔变量,如下所示:

  • 是:如果类型T是可构造的。
  • False:如果类型T是不可构造的。

下面的程序说明了C / C++中的std :: is_constructible模板:

程序:

// C++ program to illustrate
// std::is_constructible example
#include 
#include 
using namespace std;
  
// Declare structures
struct A {
};
  
struct T {
    T(int, int){};
};
  
// Driver Code
int main()
{
    cout << std::boolalpha;
  
    // Check if  is
    // constructible or not
    cout << "int: "
         << is_constructible::value
         << endl;
  
    // Check if  is
    // constructible or not
    cout << "int(float): "
         << is_constructible::value
         << endl;
  
    // Check if  is
    // constructible or not
    cout << "int(float, float): "
         << is_constructible::value
         << endl;
  
    // Check if struct T is
    // constructible or not
    cout << "T: "
         << is_constructible::value
         << endl;
  
    // Check if struct  is
    // constructible or not
    cout << "T(int): "
         << is_constructible::value
         << endl;
  
    // Check if struct  is
    // constructible or not
    cout << "T(int, int): "
         << is_constructible::value
         << endl;
    return 0;
}
输出:
int: true
int(float): true
int(float, float): false
T: false
T(int): false
T(int, int): true

参考: http://www.cplusplus.com/reference/type_traits/is_constructible/

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”