私が理解している限り(少なくとも について)、自明でない場合(暗黙的に生成されたまたは) c++14
、デストラクタは存在できません。自明でないデストラクタを持つ構造体のコンストラクタを宣言するポイントは何ですか?constexpr
=default
constexpr
struct X {
int a_;
constexpr X(int a) : a_{a} {}
// constexpr ~X(){}; // Error dtor cannot be marked constexpr
// ~X(){}; // causes error at y declaration: temporary of non-literal type ‘X’
// in a constant expression .
};
template <int N> struct Y {};
int main() {
Y<X{3}.a_> y; // OK only if the destructor is trivial
(void)y;
}
// tested with c++14 g++-5.1.0 and clang++ 3.5.0
たとえば、デストラクタが明らかに明示的に定義されていても、std::unique_ptr
いくつかのコンストラクタ constexpr
(デフォルトおよび)があります(オブジェクトがオブジェクトは空の状態にあり、私が見たように、空のデストラクタでさえオブジェクトをコンパイル定数式で使用することはできません)nullptr_t
nullptr
もう 1 つの例は、std::variantの提案です。ほとんどすべてのコンストラクターconstexpr
がありますが、デストラクタには署名が~variant()
あり、それを行う必要があります。call get<T_j> *this).T_j::~T_j() with j being index().
私は何が欠けていますか?