[libcxx] Add <experimental/any> v2.
Summary: This patch adds the second revision of <experimental/any>. I've been working from the LFTS draft found at this link. https://rawgit.com/cplusplus/fundamentals-ts/v1/fundamentals-ts.html#any Reviewers: danalbert, jroelofs, K-ballo, mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6762 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@243728 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++98, c++03, c++11
|
||||
|
||||
// <experimental/any>
|
||||
|
||||
// any::clear() noexcept
|
||||
|
||||
#include <experimental/any>
|
||||
#include <cassert>
|
||||
|
||||
#include "any_helpers.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
using std::experimental::any;
|
||||
using std::experimental::any_cast;
|
||||
// empty
|
||||
{
|
||||
any a;
|
||||
|
||||
// noexcept check
|
||||
static_assert(
|
||||
noexcept(a.clear())
|
||||
, "any.clear() must be noexcept"
|
||||
);
|
||||
|
||||
assertEmpty(a);
|
||||
|
||||
a.clear();
|
||||
|
||||
assertEmpty(a);
|
||||
}
|
||||
// small object
|
||||
{
|
||||
any a((small(1)));
|
||||
assert(small::count == 1);
|
||||
assertContains<small>(a, 1);
|
||||
|
||||
a.clear();
|
||||
|
||||
assertEmpty<small>(a);
|
||||
assert(small::count == 0);
|
||||
}
|
||||
// large object
|
||||
{
|
||||
any a(large(1));
|
||||
assert(large::count == 1);
|
||||
assertContains<large>(a);
|
||||
|
||||
a.clear();
|
||||
|
||||
assertEmpty<large>(a);
|
||||
assert(large::count == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user