* [v3 PATCH] Support allocators in tuples of zero size.
@ 2016-06-05 17:59 Ville Voutilainen
2016-06-05 18:16 ` Ville Voutilainen
0 siblings, 1 reply; 3+ messages in thread
From: Ville Voutilainen @ 2016-06-05 17:59 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 772 bytes --]
All in all this is a bit inane, but the spec requires a zero-sized tuple
to provide allocator overloads for constructors, even though they do
absolutely nothing (they completely ignore the allocator). Presumably
these are also useful for some metaprogrammers I haven't heard of.
This takes us one small step further to pass libc++'s testsuite for tuple.
Tested on Linux-X64.
2016-06-05 Ville Voutilainen <ville.voutilainen@gmail.com>
Support allocators in tuples of zero size.
* include/std/tuple (tuple<>::tuple(),
tuple<>::tuple(allocator_arg_t, const _Alloc&),
tuple<>::tuple(allocator_arg_t, const _Alloc&, const tuple&),
tuple<>::tuple(allocator_arg_t, const _Alloc&, tuple&&)): New.
* testsuite/20_util/tuple/cons/allocators.cc: Adjust.
[-- Attachment #2: zero-tuple-allocators.diff --]
[-- Type: text/plain, Size: 1646 bytes --]
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 17c8204..f7805ca 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -876,6 +876,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
public:
void swap(tuple&) noexcept { /* no-op */ }
+ // We need the default since we're going to define no-op
+ // allocator constructors.
+ tuple() = default;
+ // No-op allocator constructors.
+ template<typename _Alloc>
+ tuple(allocator_arg_t __tag, const _Alloc& __a) { }
+ template<typename _Alloc>
+ tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in) { }
+ template<typename _Alloc>
+ tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in) { }
};
/// Partial specialization, 2-element tuple.
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
index 052b79f..bc45780 100644
--- a/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
@@ -162,8 +162,30 @@ void test01()
}
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using std::allocator_arg;
+ using std::tuple;
+ using std::make_tuple;
+
+ typedef tuple<> test_type;
+
+ MyAlloc a;
+
+ // default construction
+ test_type t1(allocator_arg, a);
+ // copy construction
+ test_type t2(allocator_arg, a, t1);
+ // move construction
+ test_type t3(allocator_arg, a, std::move(t1));
+ // make_tuple
+ test_type empty = make_tuple();
+}
+
int main()
{
test01();
+ test02();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [v3 PATCH] Support allocators in tuples of zero size.
2016-06-05 17:59 [v3 PATCH] Support allocators in tuples of zero size Ville Voutilainen
@ 2016-06-05 18:16 ` Ville Voutilainen
2016-06-06 16:11 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Ville Voutilainen @ 2016-06-05 18:16 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1274 bytes --]
On 5 June 2016 at 20:59, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:
> All in all this is a bit inane, but the spec requires a zero-sized tuple
> to provide allocator overloads for constructors, even though they do
> absolutely nothing (they completely ignore the allocator). Presumably
> these are also useful for some metaprogrammers I haven't heard of.
> This takes us one small step further to pass libc++'s testsuite for tuple.
>
> Tested on Linux-X64.
>
> 2016-06-05 Ville Voutilainen <ville.voutilainen@gmail.com>
>
> Support allocators in tuples of zero size.
> * include/std/tuple (tuple<>::tuple(),
> tuple<>::tuple(allocator_arg_t, const _Alloc&),
> tuple<>::tuple(allocator_arg_t, const _Alloc&, const tuple&),
> tuple<>::tuple(allocator_arg_t, const _Alloc&, tuple&&)): New.
> * testsuite/20_util/tuple/cons/allocators.cc: Adjust.
Uh, perhaps we shouldn't add a useless move constructor.
2016-06-05 Ville Voutilainen <ville.voutilainen@gmail.com>
Support allocators in tuples of zero size.
* include/std/tuple (tuple<>::tuple(),
tuple<>::tuple(allocator_arg_t, const _Alloc&),
tuple<>::tuple(allocator_arg_t, const _Alloc&, const tuple&)): New.
* testsuite/20_util/tuple/cons/allocators.cc: Adjust.
[-- Attachment #2: zero-tuple-allocators_2.diff --]
[-- Type: text/plain, Size: 1545 bytes --]
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 17c8204..7570883 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -876,6 +876,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
public:
void swap(tuple&) noexcept { /* no-op */ }
+ // We need the default since we're going to define no-op
+ // allocator constructors.
+ tuple() = default;
+ // No-op allocator constructors.
+ template<typename _Alloc>
+ tuple(allocator_arg_t __tag, const _Alloc& __a) { }
+ template<typename _Alloc>
+ tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in) { }
};
/// Partial specialization, 2-element tuple.
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
index 052b79f..bc45780 100644
--- a/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc
@@ -162,8 +162,30 @@ void test01()
}
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using std::allocator_arg;
+ using std::tuple;
+ using std::make_tuple;
+
+ typedef tuple<> test_type;
+
+ MyAlloc a;
+
+ // default construction
+ test_type t1(allocator_arg, a);
+ // copy construction
+ test_type t2(allocator_arg, a, t1);
+ // move construction
+ test_type t3(allocator_arg, a, std::move(t1));
+ // make_tuple
+ test_type empty = make_tuple();
+}
+
int main()
{
test01();
+ test02();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [v3 PATCH] Support allocators in tuples of zero size.
2016-06-05 18:16 ` Ville Voutilainen
@ 2016-06-06 16:11 ` Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2016-06-06 16:11 UTC (permalink / raw)
To: Ville Voutilainen; +Cc: libstdc++, gcc-patches
On 05/06/16 21:15 +0300, Ville Voutilainen wrote:
> {
> public:
> void swap(tuple&) noexcept { /* no-op */ }
>+ // We need the default since we're going to define no-op
>+ // allocator constructors.
>+ tuple() = default;
>+ // No-op allocator constructors.
>+ template<typename _Alloc>
>+ tuple(allocator_arg_t __tag, const _Alloc& __a) { }
>+ template<typename _Alloc>
>+ tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in) { }
Please remove the names of the unused parameters, so we don't get
warnings with -Wsystem-headers -Wunused-parameter.
OK with that change, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-06 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-05 17:59 [v3 PATCH] Support allocators in tuples of zero size Ville Voutilainen
2016-06-05 18:16 ` Ville Voutilainen
2016-06-06 16:11 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).