2014-07-23 3 views
3

를 튜플초기화 튜플은

/usr/include/c++/4.6/tuple:100:4: error: binding of reference to type 'float' to 
a value of type 'const float' drops qualifiers 

: _M_head_impl(std::forward<_UHead>(__h)) { } 

^ ~~~~~~~~~~~~~~~~~~~~~~~~~ 

//snip... 

/usr/include/c++/4.6/tuple:257:11: note: in instantiation of function template 
specialization 'std::_Tuple_impl<0, float &, float &, float &>::_Tuple_impl 
<float, float, float>' requested here 

: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) 

^ 

18 : note: in instantiation of function template specialization 
'std::tuple::tuple' requested here 

Vec3Ref bar (foo); 

^ 

내가 찾은 가장 가까운 것은 this question이지만, 문제가있는 것 같습니다 값이 std::make_tuple 인 튜플로 초기화하는 것이 좋습니다. 그러나 foo은 대개는 lvalue입니다. 왜 이것이 작동하지 않습니까? 이 방법과 std::tie의 차이점은 무엇입니까? 2014년 7월 23일에서

+2

Vec3 & Vec3Ref의 문제점은 무엇입니까? –

+0

@ DieterLücking 지정 가능한 스윕. 어디에도 존재하지 않으면 외부 구조에 대한 참조를 만들 수 없습니다. – Dan

+0

@ShafikYaghmour Clang 3.0.6. – Dan

답변

1

Github의 흘수 [tuple.cnstr]

template <class... UType> constexpr tuple(tuple<UTypes...>&& u); 

18이 필요합니다sizeof...(Types) == sizeof...(UTypes). is_constructible<Ti, Ui&&>::value은 모두 에 대해 true입니다.

20비고 : UTypes의 각 유형 Types의 해당 형식으로 암시 적으로 전환하지 않는 한이 생성자는 오버로드 확인에 참여하지 않는다.

비고 : 섹션은 SFINAE를 정의합니다. 과 다른 점은 대신 is_convertible을 사용해야하므로 섹션은 섹션입니다. float가 xValue가 float 좌변 기준에 결합 될 수 없다 :

is_convertible [meta.rel/4

영업의 예에서

이 거짓 인 체크 is_convertible<float, float&>, 리드 주어진 다음의 함수 프로토 타입 : 템플릿 전문화에 대한

template <class T> 
add_rvalue_reference_t<T>::type create() noexcept; 

술어 조건

float& test() { 
    return create<float>(); 
} 

이를 변이이며, 여기에

To test() { 
    return create<From>(); 
} 

: 다음과 같은 VODE가 잘 형성 될 경우에만 경우 5,163,210 함수의 반환 형식에 대한 암시 적 변환을 포함하여, 만족하여야한다 형성된 create<float>()float&&, 즉 x 값을 반환합니다. 결과는 왼쪽 값 참조에 바인딩 할 수 없습니다.


tuple의 구성이 완벽하지 않다는 것은 잘 알려져있다. 예를 들어 proposal N3680을 참조하십시오. 주소는 LWG defect 2051입니다.

그러나 그 중 OP에서는 문제를 해결하지 못했습니다.

+0

이 작업을 수행하려면 튜플 인수의 값 범주를 포함하고이를 튜플 요소 유형의 참조 한정자와 병합해야합니다. 문제는'tuple '->'tuple '에서도 발생해야합니다. – dyp

+0

[라이브 예제] (http://coliru.stacked-crooked.com/a/aa584e04353ad153) – dyp