4
최근에 하나의 요소에 std::tuple<>
을 사용하는 데 문제가 있음을 발견했습니다. 나는 타입 소거를위한 클래스를 생성하고 N 개의 참조 된 객체를 유지했다. 그러나 참조 카운트 된 개체가 std::tuple<>
에있는 유일한 개체 인 경우 유지되지 않습니다.std :: tuple <> 중 하나의 std :: shared_ptr <>이 작동하지 않습니까?
내가 잘못 했나요? (엑스 코드 8.0 테스트)
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;
};
예 : 내 관점에서
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에서 작동하지만 clang에서는 작동하지 않습니다. – Danh
@ Danh Thanks! 나는 그 때 미치지 않을 것이다. 누구에게 이것을보고합니까? –
트렁크에 고정 된 것 같습니다 (http://melpon.org/wandbox/permlink/8YUeWAcj3PzyWphs). –