Files
libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp
Eric Fiselier e739d54f86 [libcxx] Add std::any
Summary:
This patch adds std::any by moving/adapting <experimental/any>.

This patch also implements the std::any parts of p0032r3 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0032r3.pdf)
and LWG 2509 (http://cplusplus.github.io/LWG/lwg-defects.html#2509).

I plan to push it in a day or two if there are no comments.


Reviewers: mclow.lists, EricWF

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22733

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@278310 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 03:13:11 +00:00

65 lines
1.2 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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, c++14
// <any>
// any::has_value() noexcept
#include <any>
#include <cassert>
#include "any_helpers.h"
int main()
{
using std::any;
// noexcept test
{
any a;
static_assert(noexcept(a.has_value()), "any::has_value() must be noexcept");
}
// empty
{
any a;
assert(!a.has_value());
a.reset();
assert(!a.has_value());
a = 42;
assert(a.has_value());
}
// small object
{
small const s(1);
any a(s);
assert(a.has_value());
a.reset();
assert(!a.has_value());
a = s;
assert(a.has_value());
}
// large object
{
large const l(1);
any a(l);
assert(a.has_value());
a.reset();
assert(!a.has_value());
a = l;
assert(a.has_value());
}
}