Question:
I’m trying to write a wrapper class that conditionally disables four special member functions (copy construct, move construct, copy assignment and move assignment), below is a quick draft I used for testing purposes:<move_ctor, move_asgn>
, <copy_ctor, move_asgn>
and <copy_ctor, move_ctor, move_asgn>
). Specifically, the assertion in the code below fails, which leads me to believe that for some reason the defaulted move assignment operator is not deleted, in the move_ctor
partial specialisation of _disabled_wrapper
, even though its non-static member _parent
has its move assignment deleted. cppreference.com states:The implicitly-declared or defaulted move assignment operator for class T is defined as deleted if any of the following is true: T has a non-static data member that is const; T has a non-static data member of a reference type; T has a non-static data member that cannot be move-assigned (has deleted, inaccessible, or ambiguous move assignment operator); T has direct or virtual base class that cannot be move-assigned (has deleted, inaccessible, or ambiguous move assignment operator). A deleted implicitly-declared move assignment operator is ignored by overload resolution.
Which makes me believe that, according to the standard, the move assignment operator should indeed be deleted (bullet point three). What am I missing and or, if possible, how do I make the wrapper class work as intended without manually typing all possible specialisations? Thank you.
Answer:
The last statement in your quote “A deleted implicitly-declared move assignment operator is ignored by overload resolution.” is more precisely:A defaulted move assignment operator that is defined as deleted is ignored by overload resolution.
class.copy.assign
type
has a defaulted move assignment operator which is defined as deleted because it is deleted in a base class.Therefore, this operator is ignored by overload resolution.
Therefore, assignment from an rvalue selects copy assignment.
Therefore,
type
is move assignable because it is copy assignable.If you have better answer, please add a comment about this, thank you!