diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/experimental/optional/optional.object/optional.object.observe | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) |
Notes
Diffstat (limited to 'test/std/experimental/optional/optional.object/optional.object.observe')
10 files changed, 557 insertions, 0 deletions
diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/bool.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/bool.pass.cpp new file mode 100644 index 0000000000000..a3724375cf4d0 --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/bool.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr explicit optional<T>::operator bool() const noexcept; + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::experimental::optional; + + { + constexpr optional<int> opt; + static_assert(!opt, ""); + } + { + constexpr optional<int> opt(0); + static_assert(opt, ""); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/dereference.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/dereference.pass.cpp new file mode 100644 index 0000000000000..98e5dac9719ed --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/dereference.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// T& optional<T>::operator*(); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + constexpr int test() const {return 3;} + int test() {return 4;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional<X> opt(X{}); + assert((*opt).test() == 4); + } +#ifdef _LIBCPP_DEBUG + { + optional<X> opt; + assert((*opt).test() == 3); + assert(false); + } +#endif // _LIBCPP_DEBUG +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/dereference_const.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/dereference_const.pass.cpp new file mode 100644 index 0000000000000..c72a57852a327 --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/dereference_const.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr const T& optional<T>::operator*() const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + constexpr int test() const {return 3;} +}; + +struct Y +{ + int test() const {return 2;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt(X{}); + static_assert((*opt).test() == 3, ""); + } + { + constexpr optional<Y> opt(Y{}); + assert((*opt).test() == 2); + } +#ifdef _LIBCPP_DEBUG + { + const optional<X> opt; + assert((*opt).test() == 3); + assert(false); + } +#endif // _LIBCPP_DEBUG +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow.pass.cpp new file mode 100644 index 0000000000000..b17fcf8d30506 --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr T* optional<T>::operator->(); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + constexpr int test() const {return 3;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt(X{}); + static_assert(opt->test() == 3, ""); + } +#ifdef _LIBCPP_DEBUG + { + optional<X> opt; + assert(opt->test() == 3); + assert(false); + } +#endif // _LIBCPP_DEBUG +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow_const.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow_const.pass.cpp new file mode 100644 index 0000000000000..e813dd992a5b2 --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/op_arrow_const.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr const T* optional<T>::operator->() const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + constexpr int test() const {return 3;} +}; + +struct Y +{ + int test() const {return 2;} +}; + +struct Z +{ + const Z* operator&() const {return this;} + constexpr int test() const {return 1;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt(X{}); + static_assert(opt->test() == 3, ""); + } + { + constexpr optional<Y> opt(Y{}); + assert(opt->test() == 2); + } + { + constexpr optional<Z> opt(Z{}); + assert(opt->test() == 1); + } +#ifdef _LIBCPP_DEBUG + { + const optional<X> opt; + assert(opt->test() == 3); + assert(false); + } +#endif // _LIBCPP_DEBUG +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp new file mode 100644 index 0000000000000..e91805e9c8e5f --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// T& optional<T>::value(); + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; +using std::experimental::bad_optional_access; + +struct X +{ + X() = default; + X(const X&) = delete; + constexpr int test() const {return 3;} + int test() {return 4;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional<X> opt; + opt.emplace(); + assert(opt.value().test() == 4); + } + { + optional<X> opt; + try + { + opt.value(); + assert(false); + } + catch (const bad_optional_access&) + { + } + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/value_const.fail.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/value_const.fail.cpp new file mode 100644 index 0000000000000..f0f8af6da45df --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/value_const.fail.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr const T& optional<T>::value() const; + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + constexpr int test() const {return 3;} + int test() {return 4;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt; + static_assert(opt.value().test() == 3, ""); + } +#else +#error +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp new file mode 100644 index 0000000000000..39bf687ff3c5b --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// constexpr const T& optional<T>::value() const; + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; +using std::experimental::in_place_t; +using std::experimental::in_place; +using std::experimental::bad_optional_access; + +struct X +{ + X() = default; + X(const X&) = delete; + constexpr int test() const {return 3;} + int test() {return 4;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt(in_place); + static_assert(opt.value().test() == 3, ""); + } + { + const optional<X> opt(in_place); + assert(opt.value().test() == 3); + } + { + const optional<X> opt; + try + { + opt.value(); + assert(false); + } + catch (const bad_optional_access&) + { + } + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/value_or.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/value_or.pass.cpp new file mode 100644 index 0000000000000..6118c44bb5baa --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/value_or.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class U> T optional<T>::value_or(U&& v) &&; + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; +using std::experimental::in_place_t; +using std::experimental::in_place; + +struct Y +{ + int i_; + + Y(int i) : i_(i) {} +}; + +struct X +{ + int i_; + + X(int i) : i_(i) {} + X(X&& x) : i_(x.i_) {x.i_ = 0;} + X(const Y& y) : i_(y.i_) {} + X(Y&& y) : i_(y.i_+1) {} + friend constexpr bool operator==(const X& x, const X& y) + {return x.i_ == y.i_;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional<X> opt(in_place, 2); + Y y(3); + assert(std::move(opt).value_or(y) == 2); + assert(*opt == 0); + } + { + optional<X> opt(in_place, 2); + assert(std::move(opt).value_or(Y(3)) == 2); + assert(*opt == 0); + } + { + optional<X> opt; + Y y(3); + assert(std::move(opt).value_or(y) == 3); + assert(!opt); + } + { + optional<X> opt; + assert(std::move(opt).value_or(Y(3)) == 4); + assert(!opt); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/experimental/optional/optional.object/optional.object.observe/value_or_const.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.observe/value_or_const.pass.cpp new file mode 100644 index 0000000000000..d51f18abbd28b --- /dev/null +++ b/test/std/experimental/optional/optional.object/optional.object.observe/value_or_const.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class U> constexpr T optional<T>::value_or(U&& v) const&; + +#include <experimental/optional> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct Y +{ + int i_; + + constexpr Y(int i) : i_(i) {} +}; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} + constexpr X(const Y& y) : i_(y.i_) {} + constexpr X(Y&& y) : i_(y.i_+1) {} + friend constexpr bool operator==(const X& x, const X& y) + {return x.i_ == y.i_;} +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + constexpr optional<X> opt(2); + constexpr Y y(3); + static_assert(opt.value_or(y) == 2, ""); + } + { + constexpr optional<X> opt(2); + static_assert(opt.value_or(Y(3)) == 2, ""); + } + { + constexpr optional<X> opt; + constexpr Y y(3); + static_assert(opt.value_or(y) == 3, ""); + } + { + constexpr optional<X> opt; + static_assert(opt.value_or(Y(3)) == 4, ""); + } + { + const optional<X> opt(2); + const Y y(3); + assert(opt.value_or(y) == 2); + } + { + const optional<X> opt(2); + assert(opt.value_or(Y(3)) == 2); + } + { + const optional<X> opt; + const Y y(3); + assert(opt.value_or(y) == 3); + } + { + const optional<X> opt; + assert(opt.value_or(Y(3)) == 4); + } +#endif // _LIBCPP_STD_VER > 11 +} |