我是靠谱客的博主 清秀短靴,这篇文章主要介绍c++11新特性std::is_trivial,现在分享给大家,希望可以做个参考。

首先 std::is_trivila 定义

template< class T >
struct is_trivial;

结构成员函数: value
返回true,如果T 包含默认的构造函数。
其他情况下,返回false。
一种可能的实现方式::

template< class T >
struct is_trivial : std::integral_constant< 
    bool,
    std::is_trivially_copyable<T>::value &&
    std::is_trivially_default_constructible<T>::value 
> {};

样例:

struct A {
    A()= default;
    int m;
};

struct B {
    int m;
};

struct C{
    C(){}
    int m;
};

int main(int argc, char**argv)
{
    std::cout << std::boolalpha;
    std::cout << std::is_trivial<A>::value << 'n';
    std::cout << std::is_trivial<B>::value << 'n';
    std::cout << std::is_trivial<C>::value << 'n';
}

输出:
true
true
false

原文链接:https://blog.csdn.net/TH_NUM/article/details/95384976

最后

以上就是清秀短靴最近收集整理的关于c++11新特性std::is_trivial的全部内容,更多相关c++11新特性std内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部