Open Cirnoo opened 2 years ago
struct Test { Test() { printf("constructor\n"); }; Test(const Test &) { printf("copy constructor\n"); } Test(Test && m) { printf("move constructor\n"); } ~Test() { printf("destruct \n"); } }; int main() { promise::any a(Test{}); // 输出 // constructor // copy constructor // destruct // destruct }
C++17 的std::any是正常的,输出
constructor move constructor destruct destruct
看起来是holder类没有对右值构造进行重载。
template<typename ValueType> class holder : public placeholder { public: // structors holder(const ValueType & value) : held(value) { } public: // queries virtual type_index type() const { return type_id<ValueType>(); } virtual placeholder * clone() const { return new holder(held); } virtual any call(const any &arg) const { return any_call(held, arg); } public: // representation ValueType held; private: // intentionally left unimplemented holder & operator=(const holder &); };
确实!是没有支持
C++17 的std::any是正常的,输出
看起来是holder类没有对右值构造进行重载。