Skip to content

promise::any貌似不支持右值构造 #17

@Cirnoo

Description

@Cirnoo
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 &);
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions