Hello, I have a problem with implementing my own container similar to std :: map.

at the moment I have an iterator and const_iterator I need to make them:

  1. is_reference - here, as I understand it, you just need to return & iterator
  2. is_convertible - the biggest problem here. For example, how to do the conversion so that the code below worked, I can not imagine.

    using mapp = Map<int, int>; using mapp_it1 = mapp::const_iterator; using mapp_it2 = mapp::iterator; mapp_it1 tmp1; mapp_it2 tmp2; static_assert(std::is_convertible<mapp_it2, mapp_it1>::value, "iterator is not convertible to const iterator"); tmp1 == (mapp_it1)tmp2; //Вот этот момент tmp1 != tmp2; 

    I will be very grateful for the hint, and a possible example.

    1 answer 1

    You need to define either the mapp :: const_iterator constructor that accepts mapp :: iterator, or the cast operator for mapp :: iterator in mapp :: const_iterator

    • Is there an example of a cast operator from mapp :: iterator to mapp :: const_iterator? - Demolver
    • The @Demolver conversion operator from type T to type X is implemented as a member function in the class T as operator X() const . In the body of the function, you must provide a return of a variable of type X - αλεχολυτ