Re: downcast copy algorithm request





"Doug Harrison [MVP]" wrote:

> Or, you can write your own minimalistic input iterator adapter class, which
> you would use something like this:
>
> std::copy(
> static_cast_iterator<B*>(pa),
> static_cast_iterator<B*>(pa+1),
> pb);
>

I tried but I stumped over the following problem. I present it in an
isolated form.

template<class wrapped_t>

struct wrapper {

wrapped_t x;

wrapper(wrapped_t c): x(c) {

}

wrapper &operator =(wrapped_t c) {

x = c;

return *this;

}

operator wrapped_t &(void) {

return x;

}

operator wrapped_t const &(void) const {

return x;

}

};



inline void test_wrapper(void) {

wrapper<int> x(00);

wrapper<int *> y(00);

++x;

++y; // error C2675: unary '++' : 'wrapper<wrapped_t>' does not define this
operator or a conversion to a type acceptable to the predefined operator

}





Comeau compiles it without an error but MSVC prohibits me from incrementing
the pointer whereas it allows me to increment the integer. It does not make
sense.


.



Relevant Pages