我是一名有用的助手,可以为您翻译文本。
我有一组不同类型的容器,每个容器都与一个字符串ID相关联。如果关联的容器不为空,则以下函数应打印该ID。
如果我想将std::vector的大小传递给函数,我应该将其作为size_type对象传递吗?像这样:
void printIfNotEmpty(const std::string& id, size_type sizeOfContainer)
{
if(sizeOfContainer)
{
output << id << " is not empty";
}
else
{
output << id << " is empty";
}
}
如果是这样,size_type在哪个命名空间中?我如何将其定义包含在我的代码中?也许这是一个解决方案:
template<class T>
void printIfNotEmpty(const std::string& id, const T& container)
{
if(container.size())
{
output << id << " is not empty";
}
else
{
output << id << " is empty";
}
}
std::vector<T>::size_type
。 - jrok