4
我最近發現使用std::tuple<>
只是一個元素的問題。我創建了一個擦除類型並保留N個引用計數對象的類。但是,如果引用計數對象是std::tuple<>
中唯一的對象,則不會保留。一個std :: shared_ptr <>的std :: tuple <>不起作用?
我做錯了什麼?
class token {
public:
template<typename... Types>
token(Types... types) : _self(std::make_shared<const std::tuple<Types...>>(std::make_tuple(std::move(types)...))) {}
// Why do I need this special version of the constructor?
// Uncomment and the code will work!
//template<typename T>
//token(T t) : _self(std::make_shared<const T>(std::move(t))) {}
private:
std::shared_ptr<const void> _self;
};
例(在Xcode 8.0測試):
token make_token() {
std::shared_ptr<int> shared(new int(), [](int* i) {
// Called immediately if using only tuple constructor!
});
return token(shared);
}
token my_token = make_token(); // std::shared_ptr<> is already gone!
在gcc中工作,但不在鐺 – Danh
@Danh謝謝!那麼我不會發瘋。我向誰彙報這件事? –
似乎固定在主幹上(http://melpon.org/wandbox/permlink/8YUeWAcj3PzyWphs)。 –