我試圖用於在編譯時測試某些propierties(type_trait)variadics模板,但看來下面的代碼不能編譯C++ 11 constexpr可變參數邏輯表達式
template<typename test>
constexpr bool trait_test(){
return test::value;
}
template<typename test, typename... Others>
constexpr bool trait_test(){
return test::value&&trait_test<Others...>();
}
template<typename A, typename... Deriveds>
constexpr bool commonBaseClass{
return trait_test<std::is_base_of<A,Deriveds>...>();
}
這個問題似乎是當「其他」具有爲0的lenght有2個可能的呼叫
trait_test<typename test>
trait_test<typename test, typename... Others={}>
和編譯器不知道至極一個偷看。我當然想偷看第一個(並保持一切constexpr)
下次請在您的問題中包含http://sscce.org。這使得其他人更容易測試您的代碼。 – Xeo