2013-09-02 20:30:37 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <optional>
|
|
|
|
|
|
|
|
// ~optional();
|
|
|
|
|
2013-11-15 22:42:10 +00:00
|
|
|
#include <experimental/optional>
|
2013-09-02 20:30:37 +00:00
|
|
|
#include <type_traits>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
|
2013-11-15 22:42:10 +00:00
|
|
|
using std::experimental::optional;
|
|
|
|
|
2013-09-02 20:30:37 +00:00
|
|
|
class X
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static bool dtor_called;
|
|
|
|
X() = default;
|
|
|
|
~X() {dtor_called = true;}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool X::dtor_called = false;
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER > 11
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
{
|
|
|
|
typedef int T;
|
|
|
|
static_assert(std::is_trivially_destructible<T>::value, "");
|
2013-11-15 22:42:10 +00:00
|
|
|
static_assert(std::is_trivially_destructible<optional<T>>::value, "");
|
2013-09-02 20:30:37 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
typedef double T;
|
|
|
|
static_assert(std::is_trivially_destructible<T>::value, "");
|
2013-11-15 22:42:10 +00:00
|
|
|
static_assert(std::is_trivially_destructible<optional<T>>::value, "");
|
2013-09-02 20:30:37 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
typedef X T;
|
|
|
|
static_assert(!std::is_trivially_destructible<T>::value, "");
|
2013-11-15 22:42:10 +00:00
|
|
|
static_assert(!std::is_trivially_destructible<optional<T>>::value, "");
|
2013-09-02 20:30:37 +00:00
|
|
|
{
|
|
|
|
X x;
|
2013-11-15 22:42:10 +00:00
|
|
|
optional<X> opt{x};
|
2013-09-02 20:30:37 +00:00
|
|
|
assert(X::dtor_called == false);
|
|
|
|
}
|
|
|
|
assert(X::dtor_called == true);
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_STD_VER > 11
|
|
|
|
}
|