是否可以通过 value_type
专门化 Iterator 模板参数?
我有一个具有以下原型(prototype)的函数。
template<typename InputIterator>
void f(InputIterator first, InputIterator last);
如果 InputIterator::value_type
是 SomeSpecificType.
最佳答案
您可以使用一些中间结构来获得您需要的部分模板特化。像这样的东西应该可以解决问题
template<typename T, typename V>
struct f_impl
{
static void f( T first, T last ) {...}; //Default version
};
template<typename T>
struct f_impl<T, SomeSpecificType>
{
static void f(T first,T last) {...}; //Specialisation
};
template<typename InputIterator> void f(InputIterator first, InputIterator last)
{
f_impl<
InputIterator,
typename std::iterator_traits<InputIterator>::value_type
>::f(first,last);
};
关于c++ - 如何在 C++ 中通过其值类型专门化迭代器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6273793/