【发布时间】:2011-06-11 21:59:55
【问题描述】:
我正在回答this 的问题。我意识到当我不知道自己在说什么时,我会说不出话来。
所以我的问题是这样的。是否可以将这些功能合并为一个? (别担心这是一个已经存在的函数的完全复制,我只是用它作为例子)
template <class iterType1, class iterType2, class boolPred>
bool equal(iterType1 begin, iterType1 end, iterType2 e, boolPred pred){
while(begin != end){
if(!pred(*begin, *e))
return false;
++begin;
++e;
}
return true;
}
template <class iterType1, class iterType2>
bool equal(iterType1 begin, iterType1 end, iterType2 e){
return equal(begin, end, e, std::equal_to<decltype(*begin)>());
}
此外,甚至可以在不使用 C++0x 特性(decltype)的情况下重用第一个中的代码。
【问题讨论】:
标签: c++ templates default-value