I don't see why move-only templates can not be extended by copy-ctor having a static_assert
(like in the code below) in order to be used with std::any
#include <any>
#include <cassert>
namespace detail{
template<typename T=int>
struct MoveOnly
{
MoveOnly() = default;
MoveOnly(MoveOnly const&) {static_assert(sizeof(T)!=sizeof(T),"");}
MoveOnly(MoveOnly &&) = default;
MoveOnly &operator=(MoveOnly const&) {static_assert(sizeof(T)!=sizeof(T),"");}
MoveOnly &operator=(MoveOnly &&) = default;
};
}
using MoveOnly = detail::MoveOnly<>;
static_assert(std::is_copy_constructible<MoveOnly>::value,"");
int main() {
MoveOnly a;
//std::any any(std::move(a)); //<- compile error
return 0;
}
In std::any::any it says for ctor #4
This overload only participates in overload resolution if ... std::is_copy_constructible_v<std::decay_t<ValueType>> is true.
As far as I can see std::is_copy_constructible<MoveOnly>::value
gives true and copy-ctor is never being called. So how is it possible that the compiler still complains about the static_assert
inside copy-ctor?