C++中的std::is_nothrow_constructible及示例
C++ STL 中的 std::is_nothrow_constructible 模板存在于 < type_traits> 头文件中。 std::is_nothrow_constructible 模板用于检查给定的类型 T 是否可以使用一组参数构造,并且它被不会抛出异常所知。 它返回布尔值 true 如果 T 是可构造类型,则返回false。
头文件:
模板类:
语法:
参数: 模板 std::is_nothrow_constructible 接受以下参数:
- T: 它代表一个数据类型。
- Args: 代表数据类型T的列表。
返回值: 模板 std::is_nothrow_constructible 返回一个布尔变量,如下所示:
- True: 如果类型 T 是可从 Args 构造的。
- False: 如果类型 T 不可使用 Args 构造。
以下是演示 std::is_nothrow_constructible 的程序的代码:
程序 1:
程序 2:
参考资料: http://www.cplusplus.com/reference/type_traits/is_nothrow_constructible/