我有以下功能模板:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>
#include <string>
#include <vector>
template <typename Streamable>
void printall(std::vector<Streamable>& items, std::string sep = "\n")
{
for (Streamable item : items)
std::cout << item << sep;
}
#endif
现在我想设置 to 的默认值,它是一个函数,sep
而std::endl
不是std::string
. 但我也希望用户能够传入一个std::string
. 我必须如何指定参数sep
的类型以同时接受任意std::string
的以及std::endl
?