指定容器类型的迭代器类型的部分专业化 [英] partial specialization for iterator type of a specified container type

查看:126
本文介绍了指定容器类型的迭代器类型的部分专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板结构,该模板结构接受Iterator类型的模板参数. 现在,我需要将该类专门用于不同容器的迭代器. 我已经尝试过std :: vector

I have a template struct, which accepts a Iterator type for the template argument. now I need to specialize that class for iterators of different containers. I have tried with std::vector

template<typename Iterator>
struct AC {

};

template<typename T, typename Alloc>
struct AC<typename std::vector<T, Alloc>::iterator> { //this doesn't work

};

但是我得到了这个编译器错误(VS11): 'T':模板参数未在部分专业化中使用或推导

but I got this compiler error(VS11): 'T' : template parameter not used or deducible in partial specialization

有人可以告诉我为什么这不起作用吗?以及如何使其工作?

Can someone please tell me why this doesn't work? And how to make it work?

推荐答案

您无法推断出嵌套::剩余的类型.确实,您的问题毫无道理.考虑以下更简单的反例:

You can't deduce types left of a nesting ::. Indeed, your question makes no sense. Consider this simpler counter-example:

template <typename> struct Foo;
template <> struct Foo<bool> { typedef float type; };
template <> struct Foo<char> { typedef float type; };

template <typename> struct DoesntWork;

template <typename T> struct DoesntWork<typename Foo<T>::type> { };

现在,如果我说DoesntWork<float>T应该是什么?

Now if I say DoesntWork<float>, what should T be?

重点是,没有理由任何 T应该存在,而Foo<T>::type是您要匹配的东西,即使有一个,也没有理由会是唯一的.

The point is that there is no reason that any T should exist for which Foo<T>::type is a thing you want to match, and even if there were one, there's no reason why it would be unique.

这篇关于指定容器类型的迭代器类型的部分专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆