Title
reference_wrapper and function types
Status
c++11
Section
[refwrap]
Submitter
Howard Hinnant

Created on 2009-02-18.00:00:00 last changed 162 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Change [refwrap]/1 as indicated:

reference_wrapper<T> is a CopyConstructible and CopyAssignable wrapper around a reference to an object or function of type T.

Date: 2010-10-21.18:28:33

[ 2009-10 post-Santa Cruz: ]

Move to Tentatively Ready.

Date: 2009-10-14.00:00:00

[ 2009-10-14 Daniel provided de-conceptified wording. ]

Date: 2010-10-21.18:28:33

[ 2009-07 Frankfurt ]

Moved from Review to Open only because the wording needs to be tweaked for concepts removal.

Date: 2009-05-23.00:00:00

[ 2009-05-23 Alisdair adds: ]

By constraining to PointeeType we rule out the ability for T to be a reference, and call in reference-collapsing. I'm not sure if this is correct and intended, but would like to be sure the case was considered.

Is dis-allowing reference types and the implied reference collapsing the intended result?

Date: 2010-10-21.18:28:33

[ 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.

Date: 2010-10-21.18:28:33

[ Post Summit, Howard adds: ]

I agree with Peter (and Eric). I got this one wrong on my first try. Here is code that demonstrates how easy (and useful) it is to instantiate reference_wrapper with 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_wrapper instantiated with 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 types and set to Open. I'll also freely admit that I'm not positive ReferentType is the correct concept.

Date: 2012-11-04.20:01:26

[ Post Summit, Peter adds: ]

In https://svn.boost.org/trac/boost/ticket/1846 however Eric Niebler makes the very reasonable point that reference_wrapper<F>, where F is a function type, represents a reference to a function, a legitimate entity. So boost::ref was 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 simply allow reference_wrapper to be used with function types.

Date: 2010-10-21.18:28:33

[ Post Summit: ]

Jens: restricted reference to ObjectType

Recommend Review.

Date: 2009-02-18.00:00:00

The synopsis in [refwrap] says:

template <ObjectType T> class reference_wrapper
...

And then paragraph 3 says:

The template instantiation reference_wrapper<T> shall be derived from std::unary_function<T1, R> only if the type T is any of the following:

  • a function type or a pointer to function type taking one argument of type T1 and returning R

But function types are not ObjectTypes.

Paragraph 4 contains the same contradiction.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4698
2010-10-21 18:28:33adminsetmessages: + msg4697
2010-10-21 18:28:33adminsetmessages: + msg4696
2010-10-21 18:28:33adminsetmessages: + msg4695
2010-10-21 18:28:33adminsetmessages: + msg4694
2010-10-21 18:28:33adminsetmessages: + msg4693
2010-10-21 18:28:33adminsetmessages: + msg4692
2010-10-21 18:28:33adminsetmessages: + msg4691
2010-10-21 18:28:33adminsetmessages: + msg4690
2009-02-18 00:00:00admincreate