c++ - Automatic generated move operations and raw pointer members -


consider memorymappedfile class, following data members:

class memorymappedfile { .... private:     // raii wrapper os-specific raw handle (e.g. win32 handle),     // representing memory-mapped file.     handle m_handle;      // pointer file begin (first file byte).     byte* m_first;      // pointer file end (one byte past last file byte).     byte* m_last; }; 

the handle class raii wrapper specific os raw c-like handle (e.g. think of win32 handle). not copyable, movable.
instead, m_first , m_last raw pointers inside memory area mapped file content.

i'd memorymappedfile class movable (but not copyable, handle class).

if weren't raw pointers, according c++11's rules of automatic generation of move constructor member-wise moves, class automatically movable.

unfortunately, raw pointers force me write custom move constructor:

memorymappedfile::memorymappedfile(memorymappedfile&& other)     : m_handle( std::move(other.m_handle) ) {     // move m_first     m_first = other.m_first;     other.m_first = nullptr;      // move m_last     m_last = other.m_last;     other.m_last = nullptr; } 

it nice if c++ standard library had form of "dumb-as-opposed-to-smart movable" pointer, zero-overhead, raw pointers (which fine observing non-owning pointers), move operations (move constructor , move assignment) defined, such compiler can automatically generate correct move operations in classes have these pointers data members.

is there in c++ standard library, or in boost?

or there other way achieve same goal (beside writing own custom observingpointer class, wrapping raw pointers , defining move operations)?

i need "smart" pointer both copyable , movable, has well-defined moved-from state, wrote tidy_ptr "dumb" smart pointer nothing special except 0 on move. type copyable, semantics want class still need define copy operations deleted (or use std::unique_ptr no-op deleter).

i've tried convince standards committee observer_ptr, "the world's dumbest smart pointer", should have behaviour, consensus should behave built-in pointer (except zero-initialization in constructor). still think should 0 on move. paper shows non_owning_ptr alias unique_ptr no-op deleter, want.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -