This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.
reference_wrapper and function typesSection: 22.10.6[refwrap]Status:C++11Submitter: Howard HinnantOpened: 2009-02-18Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [refwrap].
View all issues withC++11 status.
Discussion:
The synopsis in 22.10.6[refwrap] says:
template <ObjectType T> class reference_wrapper...
And then paragraph 3 says:
The template instantiation
reference_wrapper<T>shall bederived fromstd::unary_function<T1, R>only if the typeTis any of the following:
- afunction type or a pointer to function type taking one argument oftype
T1and returningR
But function types are notObjectTypes.
Paragraph 4 contains the same contradiction.
[Post Summit:]
Jens: restricted reference to ObjectType
Recommend Review.
[Post Summit, Peter adds:]
Inhttps://svn.boost.org/trac/boost/ticket/1846however Eric Niebler makes the very reasonable point that
reference_wrapper<F>,whereFis a function type, represents a reference to a function,a legitimate entity. Soboost::refwas changed to allow it.http://svn.boost.org/svn/boost/trunk/libs/bind/test/ref_fn_test.cpp
Therefore, I believe an alternative proposed resolution for issue 987 could simplyallow
reference_wrapperto be used with function types.
[Post Summit, Howard adds:]
I agree with Peter (and Eric). I got this one wrong on my first try. Hereis code that demonstrates how easy (and useful) it is to instantiate
reference_wrapperwith a function type:#include <functional>template <class F>void test(F f);void f() {}int main(){ test(std::ref(f));}Output (link time error shows type of
reference_wrapperinstantiatedwith function type):Undefined symbols: "void test<std::reference_wrapper<void ()()> >(std::reference_wrapper<void ()()>)",...I've taken the liberty of changing the proposed wording to allow function typesand set to Open. I'll also freely admit that I'm not positive
ReferentTypeis the correct concept.
[Batavia (2009-05):]
Howard observed that
FunctionType,a concept not (yet?) in the Working Paper,is likely the correct constraint to be applied.However, the proposed resolution provides an adequate approximation.Move to Review.
[2009-05-23 Alisdair adds:]
By constraining to
PointeeTypewe rule out the ability forTto be areference, and call in reference-collapsing. I'm not sure if this iscorrect and intended, but would like to be sure the case was considered.Is dis-allowing reference types and theimplied reference collapsing the intended result?
[2009-07 Frankfurt]
Moved from Review to Open only because the wording needs to betweaked for concepts removal.
[2009-10-14 Daniel provided de-conceptified wording.]
[2009-10 post-Santa Cruz:]
Move to Tentatively Ready.
Proposed resolution:
Change 22.10.6[refwrap]/1 as indicated:
reference_wrapper<T>is aCopyConstructibleandCopyAssignablewrapper around areference to an objector function of typeT.