mercredi 18 avril 2018

Does a deleted special class member function count as declared?

The code below does not compile, because of the absense of a move constructor and a deleted copy constructor. However, according to the C++ reference an implicit move constructor should have been provided, as my class fulfills all criteria (see below), unless a deleted copy constructor and copy assignment constructor count as declared. So my question is: does a deleted special member function count as a user-declared one?

The conditions as found on http://en.cppreference.com/w/cpp/language/move_constructor

If no user-defined move constructors are provided for a class type (struct, class, or union), and all of the following is true: there are no user-declared copy constructors; there are no user-declared copy assignment operators; there are no user-declared move assignment operators; there are no user-declared destructors;

#include <utility>

struct Test
{
    Test() {}
    Test(const Test&) = delete;
    Test& operator=(const Test& test) = delete;
    // Test(Test&&) = default;
    // Test& operator=(Test&&) = default;
};

int main()
{
    Test a;
    Test b(std::move(a));
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire