Errors with aa::copy and assignment operator
Closed this issue · 3 comments
The following simple snippet is resulting in compilation errors (on both MSVC and Clang):
using MyAny = aa::any_with< aa::copy >;
int main()
{
auto a = MyAny{ 10 };
auto b = a; // Works, but this is copy-constructor call
b = a; // This is copy-assignment operator, and fails to compile
return 0;
}
It appears that copy-construction works, but not copy-assignment.
Its not a bug, there are phrase In readme "aa::move - enables move AND copy assignment", it because of
- Strong exception guarantee
- Its strange to have copy-only type, it can be inefficient ( but makes sense if you want to reduce vtable size of smth like)
But anyway you always can emplace it (without strong exception guarantee)
Aha, ok. So as a default, I should generally specify both aa::move
and aa::copy
if I want the any to inherit whatever copy/move functionality is available on the types I put into it?
I actually had both specified initially, but I removed move
in an attempt to simplify a repro for errors I was getting. But perhaps the original errors were just a result of MSVC issues.
if I want the any to inherit whatever copy/move functionality is available on the types I put into it?
Yes, but for me default is only move(in many cases it is enough).
Also may be you are interested in functional, which is not in readme yet,
AnyAny/examples/basic_usage.hpp
Line 76 in 06ad57a
(plugins for interface parts, for example method ABC will add operator* or .ABC method without writing your type any_ and inheriting)