【发布时间】:2015-12-12 11:47:54
【问题描述】:
我有一个函子,它在 U 类型的容器上运行,该容器包含 T 类型的元素,就像这样
template<typename T, template<typename...> class U>
class asserter
{
public:
asserter(U<T> &c) : container(c) { };
void operator()(T lhs)
{
CU_ASSERT(container.find(lhs) != container.end());
};
private:
U<T> &container;
};
我可以用作
std::set<std::string> a, c;
...
asserter<std::string, std::set> ass(c);
for_each(a.begin(), a.end(), ass);
我们暂时忽略std::includes()。
如果容器是定义了U::find() 的容器,这将非常有用。如果不是,我想回退到std::find()。另一方面,如果可用,我宁愿使用U::find() 而不是std::find()。
在 C++11(或 17,如有必要)中,我能否确定 U::find() 是否可用于 U(可能仅限于 STL),如果可以使用它,否则使用 std::find()?
【问题讨论】:
标签: c++ c++11 stl traits sfinae