Variadic Templates and the "Expected Type" Error

I work (mainly for training purposes) on my own implementation tuple, and I just ran into a problem. I have the following code:

namespace Rose
{
    template<typename T>
    struct RemoveReference
    {
        typedef T Type;
    };

    template<typename T>
    struct RemoveReference<T &>
    {
        typedef T Type;
    };

    template<typename... Elems>
    class Tuple;

    template<typename First, typename... Elems>
    class Tuple<First, Elems...>
    {
    public:
        Tuple(First a, Elems... more)
            : More(more...), Element(a)
        {
        }

        Tuple<First, Elems...> & operator=(const Tuple<RemoveReference<First>::Type,
                                           RemoveReference<Elems>::Type...> & rhs)
        {
            this->Element = rhs.Element;
            this->More = rhs.More;

            return *this;
        }

    private:
        Tuple<Elems...> More;
        First Element;
    };

    template<typename Only>
    class Tuple<Only>
    {
    public:
        Tuple(Only a) : Element(a)
        {
        }

        Tuple<Only> & operator=(const Tuple<RemoveReference<Only>::Type> & rhs)
        {
            this->Element = rhs.Element;

            return *this;
        }

    private:
        Only Element;
    };
}

int main()
{
    Rose::Tuple<int, float, int> t(1, 1.f, 2);
}

This causes the following error (there are more, but this is important):

error: type / value mismatch in argument 1 in the list of template parameters for the struct Rose :: Tuple template 'error: type expected, received' Rose :: RemoveReference :: Type '

I really don’t understand what it is about. The symptom RemoveReferenceworks if one is used.

Here are two test files:

I tried this code with g ++ 4.6.1, 4.5.1 and Clang ++ 2.9.

What is the reason for these errors?

+3
1

RemoveReference<T>::Type - , typename :

        Tuple<First, Elems...> & operator=(const Tuple<typename RemoveReference<First>::Type,
                                                       typename RemoveReference<Elems>::Type...> & rhs)

, , .

+5

All Articles