[libstdc++ patch] TR1 reference_wrapper invocation, base classes

Douglas Gregor doug.gregor@gmail.com
Mon Feb 28 16:08:00 GMT 2005


This patch adds support for reference_wrapper invocation and introduces the 
right base classes and typedefs for reference_wrapper. It builds on (but does 
not include) the result_of patch I sent previously 
(http://gcc.gnu.org/ml/libstdc++/2005-02/msg00250.html) and fixes one bug in 
that patch: result_of did not do the right thing for member data pointers, 
but now it does.

The repetition code in tr1/functional that includes tr1/functional_iterate.h 
many times has been moved into tr1/repeat.h, because it is needed for files 
other than tr1/functional_iterate.h; you now define a macro 
(_GLIBCXX_REPEAT_HEADER) and include tr1/repeat.h when you need to repeat 
code.

There is a _lot_ of metaprogramming in this patch; much more so than I had 
expected, and that makes the code a little bit hairy. There are two major 
complicating factors:
  (1) reference_wrapper<T> derives from unary_function and/or binary_function 
when possible. This happens when the type T is a free or member function 
pointer, function type, or class type derived from unary_function and/or 
binary_function. I've tried to document all of the metaprogramming I had to 
do to get those right, and included the tricky test cases I could think of. 

  (2) reference_wrapper<T>::operator() has to deal with invoking member 
pointers (by wrapping in mem_fn), function objects, and function references. 
There is some SFINAE/enable_if magic in the __invoke function to decide 
between these options.

There are a few other trivial changes:
  - Shortened long lines 
  - Fixed typos and an incorrect e-mail address in some headers/tests

Tested on i686-pc-linux-gnu with no failures. ChangeLog below.

Ok?

 Doug

2005-02-28      Douglas Gregor <doug.gregor@gmail.com>

 * include/tr1/functional (_Has_result_type): Cleanup.
 (_Result_of_impl): Handle member data pointers correctly.
 (reference_wrapper): Support invocation.
 Move repetition code into new file include/tr1/repeat.h.
 * include/tr1/functional_iterate.h (reference_wrapper): Support
 invocation.  Cleanup long lines.
 * include/tr1/ref_wrap_iterate.h (reference_wrapper): Declare
 invocation operators.
 * include/tr1/repeat.h: Code repetition header.
        * include/Makefile.am: Add ref_wrap_iterate.h, repeat.h
 * include/Makefile.in: Add ref_wrap_iterate.h, repeat.h
 * testsuite/tr1/3_function_objects/reference_wrapper/invoke.cc:
 New test of reference_wrapper invocation.
 * testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc:
 New test of reference_wrapper typedefs and base classes.
 * testsuite/tr1/3_function_objects/result_of.cc: Trivial cleanup
 (e-mail address).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tr1_ref_wrap.patch
Type: text/x-diff
Size: 97646 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050228/96fb05c1/attachment.bin>


More information about the Libstdc++ mailing list