Question

Sorry for this very vague title, it's very hard to describe.

The error I'm stuck with is this, I have no idea what it means:

carray.h:176: error: ‘typename Carray<T, Allocator>::is_iterator’ names ‘template<class T, class Allocator> template<class I, bool check> struct Carray<T, Allocator>::is_iterator’, which is not a type

I have this snippet to detect if something is an iterator and use the correct overload (http://stackoverflow.com/questions/6050441/why-does-this-constructor-overload-resolve-incorrectly). This compiles:

template<class T> class Carray {
private:
    // uses SFINAE to determine if the passed in type is indeed an iterator
    template<class It>
    class is_iterator_impl {
    private:
        typedef char yes[1];
        typedef char no[2];

        template<class C>
        static yes& _test(typename C::iterator_category*);

        template<class>
        static no& _test(...);
    public:
        static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
    };

    template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
    template<class It> struct is_iterator<It*, false> { typedef void type; };
    template<class It> struct is_iterator<It, false> { };

public:
    template<class It>
    Carray(It first, It last, typename is_iterator<It>::type *dummy = 0) {
        // create array from 2 iterators
    }
};

Now I wanted to separate implementation from the declarations, and I tried this, but I got the error:

template<class T> class Carray {
private:
    // uses SFINAE to determine if the passed in type is indeed an iterator
    template<class It> class is_iterator_impl;
    template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
    template<class It> struct is_iterator<It*, false> { typedef void type; };
    template<class It> struct is_iterator<It, false> { };
public:
    template<class It> Carray(It first, It last, typename is_iterator<It>::type *dummy = 0);
};

template<class T>
template<class It>
Carray<T>::Carray(It first, It last, typename Carray<T>::is_iterator<It>::type *dummy) {
    // create array from 2 iterators - ERROR IN THIS DEFINITION
}

template<class T>
template<class It>
class Carray<T>::is_iterator_impl {
private:
    typedef char yes[1];
    typedef char no[2];

    template<class C>
    static yes& _test(typename C::iterator_category*);

    template<class>
    static no& _test(...);
public:
    static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
};

I'm using g++ 4.5.5.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top