Modify

Opened 3 years ago

Last modified 3 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@…> 3 years ago.
test.cpp (717 bytes) - added by Christopher <kemsleyc@…> 3 years ago.
diff.txt (604 bytes) - added by Christopher <kemsleyc@…> 3 years ago.

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by Christopher <kemsleyc@…>

Attachment: ref.hpp added

Changed 3 years ago by Christopher <kemsleyc@…>

Attachment: test.cpp added

Changed 3 years ago by Christopher <kemsleyc@…>

Attachment: diff.txt added

comment:1 Changed 3 years ago by viboes

Component: Nonebind
Owner: set to Peter Dimov

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Peter Dimov.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.