I’m working (mainly for learning purposes) on own implementation of tuple and I’ve just encountered a problem. I have 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);
}
Which causes following error (there are more of them, but this one is essential):
error: type/value mismatch at argument 1 in template parameter list for ‘template struct Rose::Tuple’
error: expected a type, got ‘Rose::RemoveReference::Type’
I don’t really understand what’s this about. The RemoveReference trait works, when used alone.
Here are two testcases:
I have tried this code with G++ 4.6.1, 4.5.1 and Clang++ 2.9.
What’s the reason for those errors to appear?
RemoveReference<T>::Typeis a dependent type, so you need to addtypenamehere:and probably other places.