One small error: Mark the move constructor as
noexcept
, otherwise there are situations where it won’t be used there are situations where it won’t be used. The linked case is different since the class has a copy-constructor, yet I can imagine that there are still situations where it matters, especially since your copycon isn’t deleted, just private and undefined.Why is the destructor virtual? If the example is supposed to be minimal then this might be distracting.
In
generate_it
:return std::move(Moveable(foo));
The
std::move
here is redundant, since you are returning a temporary. What’s more, the explicit constructor call is redundant too, since the constructor isn’t marked asexplicit
. Justreturn foo;
will do.The
find_if
call could be replaced by vanillafind
, using temporary construction again:auto that = find(v.begin(), v.end(), target);
Finally, in the
sort
call, why aren’t the arguments declaredconst&
? Granted, makes the line even longer as it stands this is inconsistent with the const-correctness illustrated in thefind_if
call.
One small error: Mark the move constructor as
noexcept
, otherwise there are situations where it won’t be used. The linked case is different since the class has a copy-constructor, yet I can imagine that there are still situations where it matters, especially since your copycon isn’t deleted, just private and undefined.Why is the destructor virtual? If the example is supposed to be minimal then this might be distracting.
In
generate_it
:return std::move(Moveable(foo));
The
std::move
here is redundant, since you are returning a temporary. What’s more, the explicit constructor call is redundant too, since the constructor isn’t marked asexplicit
. Justreturn foo;
will do.The
find_if
call could be replaced by vanillafind
, using temporary construction again:auto that = find(v.begin(), v.end(), target);
Finally, in the
sort
call, why aren’t the arguments declaredconst&
? Granted, makes the line even longer as it stands this is inconsistent with the const-correctness illustrated in thefind_if
call.
One small error: Mark the move constructor as
noexcept
, otherwise there are situations where it won’t be used. The linked case is different since the class has a copy-constructor, yet I can imagine that there are still situations where it matters, especially since your copycon isn’t deleted, just private and undefined.Why is the destructor virtual? If the example is supposed to be minimal then this might be distracting.
In
generate_it
:return std::move(Moveable(foo));
The
std::move
here is redundant, since you are returning a temporary. What’s more, the explicit constructor call is redundant too, since the constructor isn’t marked asexplicit
. Justreturn foo;
will do.The
find_if
call could be replaced by vanillafind
, using temporary construction again:auto that = find(v.begin(), v.end(), target);
Finally, in the
sort
call, why aren’t the arguments declaredconst&
? Granted, makes the line even longer as it stands this is inconsistent with the const-correctness illustrated in thefind_if
call.
One small error: Mark the move constructor as
noexcept
, otherwise there are situations where it won’t be used. The linked case is different since the class has a copy-constructor, yet I can imagine that there are still situations where it matters, especially since your copycon isn’t deleted, just private and undefined.Why is the destructor virtual? If the example is supposed to be minimal then this might be distracting.
In
generate_it
:return std::move(Moveable(foo));
The
std::move
here is redundant, since you are returning a temporary. What’s more, the explicit constructor call is redundant too, since the constructor isn’t marked asexplicit
. Justreturn foo;
will do.The
find_if
call could be replaced by vanillafind
, using temporary construction again:auto that = find(v.begin(), v.end(), target);
Finally, in the
sort
call, why aren’t the arguments declaredconst&
? Granted, makes the line even longer as it stands this is inconsistent with the const-correctness illustrated in thefind_if
call.