Add support for "fancy" pointers to promise and packaged_task.

Summary:
This patch is very closely related to D4859. Please see http://reviews.llvm.org/D4859 for more information.

This patch adds support for "fancy" pointers and allocators to promise and packaged_task. The changes made to support this are exactly the same as in D4859.



Test Plan: "fancy" pointer tests were added to each constructor affected by the change.

Reviewers: danalbert, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D4862

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@220471 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-10-23 06:24:45 +00:00
parent 4e7d53664d
commit 4d2413ca4b
3 changed files with 98 additions and 30 deletions

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include "../test_allocator.h"
#include "min_allocator.h"
int main()
{
@@ -48,4 +49,36 @@ int main()
assert(f.valid());
}
assert(test_alloc_base::count == 0);
// Test with a minimal allocator
{
std::promise<int> p(std::allocator_arg, bare_allocator<void>());
std::future<int> f = p.get_future();
assert(f.valid());
}
{
std::promise<int&> p(std::allocator_arg, bare_allocator<void>());
std::future<int&> f = p.get_future();
assert(f.valid());
}
{
std::promise<void> p(std::allocator_arg, bare_allocator<void>());
std::future<void> f = p.get_future();
assert(f.valid());
}
// Test with a minimal allocator that returns class-type pointers
{
std::promise<int> p(std::allocator_arg, min_allocator<void>());
std::future<int> f = p.get_future();
assert(f.valid());
}
{
std::promise<int&> p(std::allocator_arg, min_allocator<void>());
std::future<int&> f = p.get_future();
assert(f.valid());
}
{
std::promise<void> p(std::allocator_arg, min_allocator<void>());
std::future<void> f = p.get_future();
assert(f.valid());
}
}

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include "../../test_allocator.h"
#include "min_allocator.h"
class A
{
@@ -94,4 +95,30 @@ int main()
assert(f.get() == 4);
}
assert(test_alloc_base::count == 0);
A::n_copies = 0;
A::n_moves = 0;
{
std::packaged_task<double(int, char)> p(std::allocator_arg,
bare_allocator<void>(), A(5));
assert(p.valid());
std::future<double> f = p.get_future();
p(3, 'a');
assert(f.get() == 105.0);
assert(A::n_copies == 0);
assert(A::n_moves > 0);
}
A::n_copies = 0;
A::n_moves = 0;
{
std::packaged_task<double(int, char)> p(std::allocator_arg,
min_allocator<void>(), A(5));
assert(p.valid());
std::future<double> f = p.get_future();
p(3, 'a');
assert(f.get() == 105.0);
assert(A::n_copies == 0);
assert(A::n_moves > 0);
}
A::n_copies = 0;
A::n_moves = 0;
}