I created a class which contains 3 elements of the same type (something like std::pair<T,std::pair<T,T>>
). Moreover I prepared it for use for(auto&var:t)
But I don't know if I did it safely.
template <class T>
class Troika
{
public:
Troika(const T& f, const T& s, const T& t)
:first(f), second(s), third(t) {}
Troika(){}
T first;
T second;
T third;
typedef T* iterator;
typedef const T* const_iterator;
iterator begin()
{
return &first;
}
const_iterator begin() const
{
return &first;
}
iterator end()
{
return &third+1;
}
const_iterator end() const
{
return &third + 1;
}
};
I mean about this part: return &third + 1;
. I know that if somebody have not huge knowledge about arithmetic of pointers in c++, it is really dangerous. Are these elements alocated one by one near each other?