mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
Add tests to check that swap(std::function, std::function) is noexcept. This is LWG#2062, but we already do this. No changes to the library, just adding tests.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283780 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,13 +12,14 @@
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
||||
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "count_new.hpp"
|
||||
|
||||
class A
|
||||
@@ -63,6 +64,9 @@ int main()
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = A(2);
|
||||
#if TEST_STD_VER >= 11
|
||||
static_assert(noexcept(swap(f1, f2)), "" );
|
||||
#endif
|
||||
assert(A::count == 2);
|
||||
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
@@ -78,6 +82,9 @@ int main()
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = g;
|
||||
#if TEST_STD_VER >= 11
|
||||
static_assert(noexcept(swap(f1, f2)), "" );
|
||||
#endif
|
||||
assert(A::count == 1);
|
||||
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
@@ -93,6 +100,9 @@ int main()
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = A(1);
|
||||
#if TEST_STD_VER >= 11
|
||||
static_assert(noexcept(swap(f1, f2)), "" );
|
||||
#endif
|
||||
assert(A::count == 1);
|
||||
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
@@ -108,6 +118,9 @@ int main()
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = h;
|
||||
#if TEST_STD_VER >= 11
|
||||
static_assert(noexcept(swap(f1, f2)), "" );
|
||||
#endif
|
||||
assert(A::count == 0);
|
||||
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
|
Reference in New Issue
Block a user