Opened 8 years ago

Last modified 8 years ago

#10277 new Feature Requests

reference_wrapper & implicit conversion to parent types

Reported by: Christopher <kemsleyc@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: bind
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

I propose a change to reference_wrapper which enables implicit conversion to references and reference_wrappers of base types.

One motivation for this is an unconventional use of reference_wrapper:

Many common library functions in code have a non-trivial set of arguments, some of which being non-const references. When reading code that uses these functions, it is often difficult to tell what side-effects a library function has from call to call. Having a coding policy that mutable references must be reference_wrappers and having calling code use ref() enables readers of the callsites to clearly identify which arguments have the possibility of having side-effects.

However, this is currently not possible without creating a custom implementation of reference_wrapper.

I have attached a proposed modification to the boost 1.55.0 implementation, as well as a simple file testing the extended capability.

Attachments (3)

ref.hpp (4.4 KB ) - added by Christopher <kemsleyc@…> 8 years ago.
test.cpp (717 bytes ) - added by Christopher <kemsleyc@…> 8 years ago.
diff.txt (604 bytes ) - added by Christopher <kemsleyc@…> 8 years ago.

Download all attachments as: .zip

Change History (4)

by Christopher <kemsleyc@…>, 8 years ago

Attachment: ref.hpp added

by Christopher <kemsleyc@…>, 8 years ago

Attachment: test.cpp added

by Christopher <kemsleyc@…>, 8 years ago

Attachment: diff.txt added

comment:1 by viboes, 8 years ago

Component: Nonebind
Owner: set to Peter Dimov
Note: See TracTickets for help on using tickets.