This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] implement allocator-extended constructors in <tuple>


2011-05-30  Jonathan Wakely  <jwakely.gcc@gmail.com>

        * include/std/tuple: Implement uses-allocator construction.
        * include/bits/allocator.h (uses_allocator): Move to ...
        * include/bits/uses_allocator.h: New file.
        * include/Makefile.am: Add new header.
        * include/Makefile.in: Regenerate.
        * testsuite/20_util/uses_allocator/cons_neg.cc: New.
        * testsuite/20_util/uses_allocator/construction.cc: New.
        * testsuite/20_util/tuple/cons/allocate_noncopyable.cc: New.
        * testsuite/20_util/tuple/cons/allocators.cc: New.

Tested x86_64-linux, committed to trunk.

I move the uses_allocator code to a separate header because <tuple>
only needs that, not the whole of bits/allocator.h, and I defined
three tag types, __uses_alloc0, __uses_alloc1 and __uses_alloc2, which
are used to dispatch to the appropriate constructor. If uses_allocator
is false then alloc0 is used, if uses_allocator<T, Alloc> is true then
alloc1 is used if is_constructible<T, allocator_arg_t, Alloc, Args...>
is true, otherwise alloc2 is used.  The function template
__use_alloc<T, Alloc, Args...>(const Alloc&) returns a type derived
from one of those tags. The tag also holds a pointer to the allocator
if it will be used, to save passing it as a separate argument.

N.B. the code could be made simpler using delegating constructors
because the _Tuple_impl constructors taking allocator_arg_t could just
pass their arguments to _Head_base and then _Head_base could call
__use_alloc and dispatch to the appropriate delegated constructor.
That can be changed later when G++ supports delegating ctors.

Attachment: tuple-alloc.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]