【发布时间】:2016-11-17 21:23:05
【问题描述】:
在网上搜索了一整天未成功的实用解决方案来解决我的问题后,我决定在这里发布我的问题,以阐明我的目标,我提供了这个简单的代码:
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 }。
任何建议或解决方案都是相当重要的。
【问题讨论】: