别人项目里stl源码的问题
template::value, int>::type = 0>
Vector(Iter first, Iter last) // range constructor 将迭代器所指向的元素[first ,last)拷贝过来
{
std::cout << "range constructor调用" << std::endl;
MYSTL_DEBUG(!(last < first));
range_init(first, last);
}
有没有大佬解释一下这里的typename std::enable_if::value, int>::type = 0这模板参数第二个是什么意思?
这种语法糖,网上就有详细的博客讲解,何必跑这来问
https://blog.csdn.net/jeffasd/article/details/84667090
c++ 新特性
enable_if 听上去是个函数实际上是个函数实际上是个 struct,构造十分巧妙,第一个参数强制要求是 true,起到了 if 判断作用:如果是 false,直接跳过。