Count of parameters in a parameter pack? Is there a C++0x std lib function for this?

可紊 提交于 2019-11-29 03:26:42

Yes, you can use sizeof.... From the C++0x FCD (§5.3.3/5):

The identifier in a sizeof... expression shall name a parameter pack. The sizeof... operator yields the number of arguments provided for the parameter pack identifier. The parameter pack is expanded (14.5.3) by the sizeof... operator. [Example:

template<class... Types>
struct count {
    static const std::size_t value = sizeof...(Types);
};

end example ]

Here's a link that may help you. Sample source from link:

template<typename... Args> struct count;

template<>
struct count<> {
    static const int value = 0;
};

template<typename T, typename... Args>
struct count<T, Args...> {
    static const int value = 1 + count<Args...>::value;
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!