不成功搜索的網頁漫長的一天後的實際的解決方案,以解決我的問題,我決定張貼在這裏我的問題,澄清我的目標,我提供了這個簡單的代碼:獲取每種參數包的大小?
template<typename... types>
std::vector<SIZE_T> GetTypesSize()
{
std::vector<SIZE_T> typesSizeContainer;
typesSizeContainer.reserve(sizeof... (types));
/*
* What I want here is a mechanism to loop throw
* each element of the parameter pack to get its size
* then push it into typesSizeContainer.
* Something similar to :
* For(auto& element : types...) {
* typesSizeContainer.push(sizeof(element));
* }
*
*/
return std::move(typesSizeContainer);
}
當我把這個在此代碼函數模板:
// platform x86
std::vector<SIZE_T> tempVactor;
tempVactor = GetTypesSize<char, short, int>();
的tempVactor
的元素應該是{ 1, 2, 4 }
。
任何建議或解決方案是相當可觀的。
As @ W.F。提到你的答案提供了我正在尋找的實用解決方案,我很感激。 –
在同一行代碼中使用'sizeof'和'sizeof ...'的一個很好的例子。 – Bernard