내가 최근에 클래스가 construct
라는 특정 템플릿 정적 기능을 포함하는 경우 감지합니다 sfinae 유형의 특성을 만들려고 앞으로 :: 작동하지 않습니다.Sfinae 유형의 특성은 표준이
나는이 구현과 함께 :
template<typename T, typename... Args>
struct has_template_construct_helper {
private:
template<typename U, typename... As>
static std::true_type test(decltype(&U::template construct<As...>)*);
template<typename...>
static std::false_type test(...);
public:
using type = decltype(test<T, Args...>(nullptr));
};
template<typename T, typename... Args>
using has_template_construct = typename has_template_construct_helper<T, Args...>::type;
는 그 괜찮을 것 문질러서하고 있었다. 나는 gcc로 내 형질을 시험해보고 다음과 같이 clang을 시도했다.
struct TestStruct {
template<typename... Args>
static auto construct(int a, double b, Args... args) -> decltype(std::make_tuple(a, b, args...)) {
return std::make_tuple(1, 2.3, std::forward<Args>(args)...);
}
};
// didn't fire! Hurrah!
static_assert(has_template_construct<TestStruct, std::string>::value, "Don't pass the test");
그것은 두 컴파일러 모두에서 작동했다. Clang
내 질문은, GCC : 여기
struct TestStruct {
template<typename... Args>
static auto construct(int a, double b, Args&&... args) -> decltype(std::make_tuple(a, b, std::forward<Args>(args)...))
{
return std::make_tuple(1, 2.3, std::forward<Args>(args)...);
}
};
// fires on clang :(
static_assert(has_template_construct<TestStruct, std::string>::value, "Don't pass the test");
coliru에 코드 :
그러나, 최대한 빨리 전달 참조를 추가 할 때, 그 소리는 불평을 시작 GCC와 연타 사이에 어떤 일이 잘못된, 그리고 어떻게 내 컴파일러에서 작동하도록 내 코드를 수정할 수 있습니까?
좋아, 지금은 더 혼란 스러워요, 일을 시도했다. std::declval
을 사용할 때, 그것은 clang에서 돌아왔다!
struct TestStruct {
template<typename... Args>
static auto construct(int a, double b, Args&&... args) -> decltype(std::make_tuple(a, b, std::declval<Args>()...))
{
return std::make_tuple(1, 2.3, std::forward<Args>(args)...);
}
};
// uh?? Works in clang?
static_assert(has_template_construct<TestStruct, std::string>::value, "Don't pass the test");
의 주석을'시험 (...)'와 실제 오류가 대체하는 동안 무엇을 참조하십시오. 도움이 될 것입니다. "표준 : 앞으로 작동하지 않습니다"무엇 – skypjack
도 의미? 컴파일 타임에 알려진 결과와 함께 std :: forward를 호출 할 수없는 유형은 없습니다. – xaxxon
나는 clang의 버그라고 생각합니다. 전달 참조를 추가하면 생성 메소드에 과부하가 걸리므로 오류가 발생합니다. – Arunmu