草庐IT

constrexpr

全部标签

c++ - 为什么要为具有非平凡析构函数的类声明 constrexpr 构造函数(例如 unique_ptr、std::variant)

据我了解(至少对于c++14而言),析构函数不能是constexpr如果它不是微不足道的(隐式生成或=default)。声明constexpr有什么意义?具有非平凡析构函数的结构的构造函数?structX{inta_;constexprX(inta):a_{a}{}//constexpr~X(){};//Errordtorcannotbemarkedconstexpr//~X(){};//causeserroratydeclaration:temporaryofnon-literaltype‘X’//inaconstantexpression.};templatestructY{};i

c++ - 为什么要为具有非平凡析构函数的类声明 constrexpr 构造函数(例如 unique_ptr、std::variant)

据我了解(至少对于c++14而言),析构函数不能是constexpr如果它不是微不足道的(隐式生成或=default)。声明constexpr有什么意义?具有非平凡析构函数的结构的构造函数?structX{inta_;constexprX(inta):a_{a}{}//constexpr~X(){};//Errordtorcannotbemarkedconstexpr//~X(){};//causeserroratydeclaration:temporaryofnon-literaltype‘X’//inaconstantexpression.};templatestructY{};i