C++备忘录087:std::is

    技术2024-10-16  20

    #include <type_traits> struct A {}; struct B { B(A) {}; }; struct C { explicit C(A) {} }; static_assert(std::is_constructible_v<B, A>); static_assert(std::is_convertible_v<A, B>); static_assert(std::is_constructible_v<C, A>); static_assert(! std::is_convertible_v<A, C>);

    std::is_convertible要求转换必须是隐式的,std::is_constructible隐式显式都可以

    Processed: 0.010, SQL: 9