c++ - Returning an object reference in a wrapped temporary -


i have iterator internal contiguous memory block , when invoking operator * wrap ever iterator pointing class marshals various operations can performed on underlying type.

here's example better explain myself.

class iterator { private:     some_t* _ptr;  public: // .. wrapper<some_t&> operator *() { return wrapper<some_t&>(*_ptr); } // .. };  int main(int argc, char** argv) { auto = some_class.begin() // returns iterator above;  *it += 20; // operation invokes overload.  return 0; } 

i want have wrapper behave underlying built in type as possible (all operators, binary, unary, boolean, etc...) above has proven difficult achieve , messy, when want have wrapper<some_t*> , wrapper<some_t&> behave built in types would.

it's clear approach plain wrong, wondering if else has ideas on how achieve same goals in better way?

thank you!

are looking std::ref() ?

http://en.cppreference.com/w/cpp/utility/functional/ref

it's function returns std::reference_wrapper<t>. type, in turn, has implicit conversion bound reference type.

it isn't entirely you're looking for, might close can (and it's ready go). implicit assignment can pass function takes parameter of wrapped type, doesn't give dot access methods on underlying object. afaik that's out.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -