호환 유형의 std::tuple
에서 요소 별로 std::tuple
개 요소를 초기화 할 수 없습니다. boost::tuple
처럼 작동하지 않는 이유는 무엇입니까?std :: tuple을 호환 유형의 std :: tuple로 요소별로 생성 할 수없는 이유는 무엇입니까?
#include <tuple>
#include <boost/tuple/tuple.hpp>
template <typename T>
struct Foo
{
// error: cannot convert 'std::tuple<int>' to 'int' in initialization
template <typename U>
Foo(U &&u) : val(std::forward<U>(u)) {}
T val;
};
int main()
{
boost::tuple<Foo<int>>{boost::tuple<int>{}}; // ok
auto a = boost::tuple<int>{};
boost::tuple<Foo<int>>{a}; // ok
std::tuple<Foo<int>>{std::tuple<int>{}}; // fails with rvalue
auto b = std::tuple<int>{};
std::tuple<Foo<int>>{b}; // fails with lvalue
}
std::tuple
이 요소 현명한 건축 일을하지 않습니다 (GCC 또는 연타와 된 libstdC++ 컴파일되지 않습니다, 그러나 연타와의 libc는 ++ 오류없이 컴파일) 그리고 Foo<int>::Foo<std::tuple<int>>
대신 Foo<int>::Foo<int>
인스턴스화 . 내가 생각 std::tuple::tuple
overloads no. 4 and 5는 그 목적을 위해 정확했다 :
template <class... UTypes>
tuple(const tuple<UTypes...>& other);
template <class... UTypes>
tuple(tuple<UTypes...>&& other);
참고 : std::is_constructible<Ti, const Ui&>::value
모든 i
에 대한 true
하지 않는 한
가 오버로드 확인에 참여하지 않습니다.
std::is_constructible<Foo<int>, int>::value
은 true
입니다. GCC 템플릿 오류에서 오버로드 번호를 볼 수 있습니다. 3 :
template <class... UTypes>
explicit tuple(UTypes&&... args);
이 대신 선택됩니다. 왜?
좋아요,'-std = libstdC++'에서는 작동하지 않지만 Clang에서는'-std = libC++'와 함께 작동합니다. 구현 문제 여야합니다. – LogicStuff
gcc의 bugzilla에 버그를 제출하십시오. –
이 질문은 같은 문제가 발생하는 사람들에게 유용한 정보를 제공합니다. 문제는 표준 라이브러리 구현이 아니라 코드에 있음을 알려줍니다. 특정 구현 버그 (MinGW와'stoi' 예를 들어)에 대한 설명 인 많은 일반적인 속임수 타겟이 있습니다. –