【发布时间】:2014-08-21 01:25:06
【问题描述】:
对不起,标题太长了...请让我知道如何使它变得更好...
我有一个模板类:
template <typename T>
class Example {
...
template <typename Iterator>
void add(const Iterator begin, const Iterator end);
...
};
如何确保Iterator指向的数据类型是T?
另一个相关问题:
这个STL向量构造函数是如何实现的
template <class InputIterator>
vector (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
确保InputIterator 具有兼容的数据类型作为向量?
编辑:
有编译时解决方案吗?
【问题讨论】:
-
类似
static_assert(is_same<decltype(*begin), T>::value)的东西 -
@IgorTandetnik 可能需要
decay。
标签: c++ templates stl iterator