I recently discovered a problem with using std::tuple<> for just one element. I created a class for type erasure and retaining N number of reference counted objects. However the reference counted object is not retained if it is the only one in the 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?
template<typename T>
token(T t) : _self(std::make_shared<const T>(std::move(t))) {}
private:
std::shared_ptr<const void> _self;
};
Aucun commentaire:
Enregistrer un commentaire