I'm having trouble getting some code to work; I do not know for sure why, but I think it has to do with the way my compiler (TDM-GCC) evaluates a map iterator.
Here is my wrapper code, which I will follow by my test code:
template <typename T, bool IS_CLASS>
class Citerator;
// If we are supplied an int, char,... , we must create an iterator around it.
template <typename TYPE>
class Citerator<TYPE, false> : public std::iterator<std::input_iterator_tag, TYPE>
{
public:
Citerator(TYPE iterator):m_raw_iterator(iterator){}
Citerator(const Citerator &iterator):m_raw_iterator(iterator.m_raw_iterator){}
Citerator &operator=(const Citerator &iterator){m_raw_iterator = iterator.m_raw_iterator; return *this;}
booloperator==(const Citerator &citerator){return m_raw_iterator == citerator.m_raw_iterator;}
booloperator!=(const Citerator &citerator){return m_raw_iterator != citerator.m_raw_iterator;}
TYPE &operator*(){return m_raw_iterator;}
TYPE &operator->(){return m_raw_iterator;}
Citerator &operator++(){++m_raw_iterator; return *this;}
Citerator &operator++(int){m_raw_iterator++; return *this;}
TYPE &get(){return m_raw_iterator;}
private:
TYPE m_raw_iterator;
};
// If we are provided an iterator, we inherit from it.
template <typename TYPE>
class Citerator<TYPE, true> : public TYPE
{
public:
using TYPE::TYPE;
TYPE &get(){return *this;}
};
// The iterator that wraps around both integers and other iterators.
template <typename TYPE, bool IS_CLASS = std::is_class<TYPE>::value>
class Iterator : public Citerator<TYPE, IS_CLASS>
{
public:
using Citerator<TYPE, IS_CLASS>::Citerator;
};
error: no matching function for call to 'Iterator<std::_Rb_tree_iterator<std::pair<const long long unsigned int, std::vector<int> > > >::Iterator(std::map<long long unsigned int, std::vector<int> >::iterator)'|
note: candidate constructor (inherited) not viable: no known conversion from 'iterator' (aka '_Rb_tree_iterator<value_type>') to '_Link_type' (aka '_Rb_tree_node<std::pair<const unsigned long, std::vector<int, std::allocator<int> > > > *') for 1st argument
You are correct in that; I was thinking of the Citerator when the IS_CLASS is false.
Anyways; I added Citerator(TYPE t){*this = t;} to the Citerator IS_CLASS = true specialization; which does seem to work. I think I understand why this happened.
I'm also thinking about changing std::input_iterator_tag to std::random_access_iterator_tag ?