2
我在寫第一個可變參數函數模板。我收到錯誤error: parameter packs not expanded with ‘...’:
。可能我在這裏無法理解一些簡單的概念。我想將所有通過iterators
存入vector
。什麼是正確的方法來做到這一點?檢查等長度的STL容器的變量函數
template<typename... Iterator>
bool IsEqualLength(Iterator&... its)
{
std::vector<Iterator> vec_its {its...};
int head = vec_its.front().size();
bool is_diff_size = std::any_of(vec_its.begin(), vec_its.end(),
[&head](Iterator& cur){return cur.size() != head;});
if(is_diff_size)
{
return false;
} else {
return true;
}
}
這失敗(下GCC 4.8.4在Ubuntu)編譯:
../proc.h: In function ‘bool IsEqualLength(Iterator& ...)’:
../proc.h:32:24: error: parameter packs not expanded with ‘...’:
std::vector<Iterator> vec_its {its...};
^
../proc.h:32:24: note: ‘Iterator’
../proc.h:35:87: error: parameter packs not expanded with ‘...’: