0

也许我今天还不是全部,但我想知道如何让它发挥作用。我想对 boost 库中的 range_mutable_iterator 和 range_const_iterator 进行部分专门化,但仅适用于我宁愿避免明确提及的特定类型,而是仅在 enable_if 测试条件通过时才选择部分专门化。

我目前正在使用 MSVC 2008 并收到以下错误
ArrayType:: template parameter not used or deducible in partial specializationon type

range_mutable_iterator<
  typename enable_if<
    mpl::and_<
      mpl::has_key<some_type_map, typename remove_const<T>::type>,
      mpl::not_<is_const<T> >
    >,
    ArrayType
  >::type
>

使用 STLFilt,请注意对 T 而不是 ArrayType 的奇怪引用,我猜 STLFilt 是说它无法弄清楚 T == ArrayType..?这是我现在拥有的:

namespace boost {
template<class ArrayType>
struct range_mutable_iterator<
  typename enable_if<
    mpl::and_<
      mpl::has_key<some_type_map, typename remove_const<ArrayType>::type>,
      mpl::not_<is_const<ArrayType> >
    >,/*and_*/
    ArrayType
  >::type/*enable_if*/
>
{
  typedef MyArrayIterator<
    typename mpl::at<some_other_type_map,
      typename mpl::at<yet_another_type_map,ArrayType>::type
    >::type/*at*/
  >/*MyArrayIterator*/ type;
};
}

让 range_begin/range_end 工作目前不是问题,目标是让线条看起来像这样:

ThirdPartyArrayClass blah;
MyArrayAdapter<ThirdPartyArrayClass>::iterator iter = boost::begin(blah);

编辑:在尝试了一种我从这个答案中编辑出来的不同方法之后,我开始接受在这种情况下部分专业化是不可能的,所以我使用了一种不同的方法,涉及完全专业化和大量使用Boost.预处理器。

4

1 回答 1

0

为了对模板进行部分特化,编译器必须将实际模板参数与现有特化相匹配,以选择最佳匹配。如果专门化中的模板参数仅用作依赖类型的(模板)参数,则这是不可能的。所以,编译器抱怨,这是正确的。你唯一能做的就是以某种方式专注于你的具体ThirdPartyArrayClass类型。

于 2010-08-04T01:41:48.757 回答