views:

53

answers:

1

Maybe I'm not all there today, but I'm wondering how to get this to work. I'd like to partially specialize range_mutable_iterator and range_const_iterator from the boost library but only for specific types that I'd rather avoid mentioning explicitly, instead only letting the partial specialization be chosen if the enable_if test criteria pass.

I'm currently using MSVC 2008 and am receiving the following error:
ArrayType: template parameter not used or deducible in partial specialization on 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
>

Using STLFilt, notice the odd reference to T instead of ArrayType, I'm guessing STLFilt is saying it can't figure out that T == ArrayType..? Here's what I have right now:

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;
};
}

Getting range_begin/range_end working isn't currently an issue, the goal is to have a line work that looks like this:

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

Edit: After having tried a different approach which I've edited out of this answer, I came to accept that partial specialization in this case just isn't possible, so I've used a different approach which involves full specialization and heavy use of Boost.Preprocessor.

A: 

In order to partially specialize a template the compiler must match the actual template arguments to the existing specializations, with the aim to select the best match. This is just not possible if the template argument in the specialization is used just as the (template) parameter to a dependent type. So, the compiler complains, and rightly so. The only thing you can do is to somehow specialize on your concrete ThirdPartyArrayClass type.

hkaiser