mirror of
https://github.com/wqking/eventpp.git
synced 2024-12-25 23:30:49 +08:00
Make AnyData not copy-constructible
This commit is contained in:
parent
ca34f0ef37
commit
b25e2703a5
@ -75,7 +75,6 @@ void funcMoveConstruct(void * object, void * buffer)
|
||||
struct AnyDataFunctions
|
||||
{
|
||||
void (*free)(void *);
|
||||
void (*copyConstruct)(void *, void *);
|
||||
void (*moveConstruct)(void *, void *);
|
||||
};
|
||||
|
||||
@ -84,7 +83,6 @@ const AnyDataFunctions * doGetAnyDataFunctions()
|
||||
{
|
||||
static const AnyDataFunctions functions {
|
||||
&funcFreeObject<T>,
|
||||
&funcCopyConstruct<T>,
|
||||
&funcMoveConstruct<T>
|
||||
};
|
||||
return &functions;
|
||||
@ -137,24 +135,14 @@ public:
|
||||
new (buffer.data()) U(std::forward<T>(object));
|
||||
}
|
||||
|
||||
AnyData(const AnyData & other) : functions(other.functions), buffer() {
|
||||
if(functions != nullptr) {
|
||||
functions->copyConstruct(other.buffer.data(), buffer.data());
|
||||
}
|
||||
}
|
||||
|
||||
AnyData(AnyData & other) : functions(other.functions), buffer() {
|
||||
if(functions != nullptr) {
|
||||
functions->copyConstruct(other.buffer.data(), buffer.data());
|
||||
}
|
||||
}
|
||||
|
||||
AnyData(AnyData && other) : functions(other.functions), buffer() {
|
||||
if(functions != nullptr) {
|
||||
functions->moveConstruct(other.buffer.data(), buffer.data());
|
||||
}
|
||||
}
|
||||
|
||||
AnyData(const AnyData & other) = delete;
|
||||
AnyData(AnyData & other) = delete;
|
||||
AnyData & operator = (const AnyData & other) = delete;
|
||||
AnyData & operator = (AnyData && other) = delete;
|
||||
|
||||
|
@ -60,10 +60,10 @@ TEST_CASE("AnyData, unique_ptr")
|
||||
Data data(Ptr(new int(5)));
|
||||
REQUIRE(data.isType<Ptr>());
|
||||
REQUIRE(*data.get<Ptr>() == 5);
|
||||
Data data2(data);
|
||||
Data data2(Ptr(new int(5)));
|
||||
REQUIRE(data2.isType<Ptr>());
|
||||
REQUIRE(*data2.get<Ptr>() == 5);
|
||||
Data data3(Data(Ptr(new int(8))));
|
||||
Data data3(Ptr(new int(8)));
|
||||
REQUIRE(data3.isType<Ptr>());
|
||||
REQUIRE(*data3.get<Ptr>() == 8);
|
||||
}
|
||||
@ -79,7 +79,7 @@ TEST_CASE("AnyData, shared_ptr")
|
||||
REQUIRE(ptr.use_count() == 2);
|
||||
REQUIRE(data.isType<Ptr>());
|
||||
REQUIRE(*data.get<Ptr>() == 8);
|
||||
Data data2(data);
|
||||
Data data2(ptr);
|
||||
REQUIRE(ptr.use_count() == 3);
|
||||
REQUIRE(data2.isType<Ptr>());
|
||||
REQUIRE(*data2.get<Ptr>() == 8);
|
||||
|
Loading…
x
Reference in New Issue
Block a user