c ++ – Model Instantiation for the Nested Class

When trying to code an iterator, I have the following structure:

model  class mything {
unsigned key typedef;
public:
model  class myiter {
key pos;
public:
...
}
using iterator = myiter;
using const_iterator = myiter;
using reverse_iterator = std :: reverse_iterator;
using const_reverse_iterator = std :: reverse_iterator;

iterator start () {return {0}; }
...
};

and would like to add the traits by declaring std :: iterator_traits<...>. I have tried

model struct std :: iterator_traits <typename mything:: myiter template> {...}

however, this results in a compiler error: "Non-deductible template parameters in partial specialization:" I just tried

model struct std :: iterator_traits <typename mything:: myiter template> {...}

which at least is accepted by the compiler, but the trait is not defined, so later in std :: reverse_iterator I get the error: "no type named iterator_category & # 39; in struct std :: iterator_traits :: myiter> & # 39;
reverse_iterator class ".

The only thing that compiles, for the moment, is to explicitly state

template <> struct std :: iterator_traits <mything:: myiter> {...}

what I obviously do not want to do for all classes.

Here is an example of minimal work: change #if 0 at #if 1 produces the errors.

#understand 

model  T myobj = 0;

model  class mything {
unsigned key typedef;
public:
model  class myiter {
key pos;
public:
myiter (key _pos): pos (_pos) {}
subT & operator * () const {return myobj; }
myiter operator ++ () {return myiter (pos + 1); }
operator myiter - () {return myiter (pos-1); }
std :: ptrdiff_t operator- (const myiter & that) const {return pos-that.pos; }
};

using iterator = myiter;
using const_iterator = myiter;
using reverse_iterator = std :: reverse_iterator;
using const_reverse_iterator = std :: reverse_iterator;

iterator start () {return {0}; }
iterator end () {return {10}; }
const_iterator begin () const {return {0}; }
const_iterator end () const {return {10}; }
const_iterator cbegin () const {return begin (); }
const_iterator cend () const {return end (); }

reverse_iterator rbegin () {return reverse_iterator {end ()}; }
reverse_iterator rend () {return reverse_iterator {begin ()}; }
const_reverse_iterator rbegin () const {return const_reverse_iterator {end ()}; }
const_reverse_iterator rend () const {return const_reverse_iterator {begin ()}; }
const_reverse_iterator crbegin () const {return rbegin (); }
const_reverse_iterator crend ​​() const {return rend (); }
};

#if 0
model struct std :: iterator_traits <typename mything:: myiter template> {
using difference_type = std :: ptrdiff_t;
using size_type = std :: size_t;
using value_type = subT;
using pointer = subT *;
using reference = subT &;
using iterator_category = std :: random_access_iterator_tag;
};

#other
template <> struct std :: iterator_traits <mything:: myiter> {
using difference_type = std :: ptrdiff_t;
using size_type = std :: size_t;
using value_type = int;
using pointer = int *;
using reference = int &;
using iterator_category = std :: random_access_iterator_tag;
};

template <> struct std :: iterator_traits <mything:: myiter> {
using difference_type = std :: ptrdiff_t;
using size_type = std :: size_t;
using value_type = const int;
using pointer = const int *;
using reference = const int & &;
using iterator_category = std :: random_access_iterator_tag;
};
#end if

#understand 
#understand 
#understand 
int main (void) {
my thing thing;

std :: ostringstream s;
std :: copy (thing.cbegin (), thing.cend (), std :: ostream_iterator(s, ""));
assert (s.str () == "0 0 0 0 0 0 0 0 0 0");

s.str ("");
std :: copy (thing.rbegin (), thing.rend (), std :: ostream_iterator(s, ""));
assert (s.str () == "0 0 0 0 0 0 0 0 0 0");

auto const & ro_thing = thing;
s.str ("");
std :: copy (ro_thing.cbegin (), ro_thing.cend (), std :: ostream_iterator(s, ""));
assert (s.str () == "0 0 0 0 0 0 0 0 0 0");
s.str ("");
std :: copy (ro_thing.rbegin (), ro_thing.rend (), std :: ostream_iterator(s, ""));
assert (s.str () == "0 0 0 0 0 0 0 0 0 0");

returns 0;
}