Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
12
test/std/experimental/nothing_to_do.pass.cpp
Normal file
12
test/std/experimental/nothing_to_do.pass.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <experimental/string_view>
|
||||
|
||||
int main () {}
|
||||
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// class bad_optional_access is default constructible
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::bad_optional_access;
|
||||
bad_optional_access ex;
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// class bad_optional_access : public logic_error
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::bad_optional_access;
|
||||
|
||||
static_assert(std::is_base_of<std::logic_error, bad_optional_access>::value, "");
|
||||
static_assert(std::is_convertible<bad_optional_access*, std::logic_error*>::value, "");
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
// template <class T> constexpr bool operator==(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator==(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator == ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ == rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( !(o1 == T(1)), "" );
|
||||
static_assert ( (o2 == T(1)), "" );
|
||||
static_assert ( !(o3 == T(1)), "" );
|
||||
static_assert ( (o3 == T(2)), "" );
|
||||
static_assert ( (o3 == val), "" );
|
||||
|
||||
static_assert ( !(T(1) == o1), "" );
|
||||
static_assert ( (T(1) == o2), "" );
|
||||
static_assert ( !(T(1) == o3), "" );
|
||||
static_assert ( (T(2) == o3), "" );
|
||||
static_assert ( (val == o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator>(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator>(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( !(o1 > T(1)), "" );
|
||||
static_assert ( !(o2 > T(1)), "" ); // equal
|
||||
static_assert ( (o3 > T(1)), "" );
|
||||
static_assert ( !(o2 > val), "" );
|
||||
static_assert ( !(o3 > val), "" ); // equal
|
||||
static_assert ( !(o3 > T(3)), "" );
|
||||
|
||||
static_assert ( (T(1) > o1), "" );
|
||||
static_assert ( !(T(1) > o2), "" ); // equal
|
||||
static_assert ( !(T(1) > o3), "" );
|
||||
static_assert ( (val > o2), "" );
|
||||
static_assert ( !(val > o3), "" ); // equal
|
||||
static_assert ( (T(3) > o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator>=(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator>=(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( !(o1 >= T(1)), "" );
|
||||
static_assert ( (o2 >= T(1)), "" ); // equal
|
||||
static_assert ( (o3 >= T(1)), "" );
|
||||
static_assert ( !(o2 >= val), "" );
|
||||
static_assert ( (o3 >= val), "" ); // equal
|
||||
static_assert ( !(o3 >= T(3)), "" );
|
||||
|
||||
static_assert ( (T(1) >= o1), "" );
|
||||
static_assert ( (T(1) >= o2), "" ); // equal
|
||||
static_assert ( !(T(1) >= o3), "" );
|
||||
static_assert ( (val >= o2), "" );
|
||||
static_assert ( (val >= o3), "" ); // equal
|
||||
static_assert ( (T(3) >= o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator<=(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator<=(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( (o1 <= T(1)), "" );
|
||||
static_assert ( (o2 <= T(1)), "" ); // equal
|
||||
static_assert ( !(o3 <= T(1)), "" );
|
||||
static_assert ( (o2 <= val), "" );
|
||||
static_assert ( (o3 <= val), "" ); // equal
|
||||
static_assert ( (o3 <= T(3)), "" );
|
||||
|
||||
static_assert ( !(T(1) <= o1), "" );
|
||||
static_assert ( (T(1) <= o2), "" ); // equal
|
||||
static_assert ( (T(1) <= o3), "" );
|
||||
static_assert ( !(val <= o2), "" );
|
||||
static_assert ( (val <= o3), "" ); // equal
|
||||
static_assert ( !(T(3) <= o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator<(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator<(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( (o1 < T(1)), "" );
|
||||
static_assert ( !(o2 < T(1)), "" ); // equal
|
||||
static_assert ( !(o3 < T(1)), "" );
|
||||
static_assert ( (o2 < val), "" );
|
||||
static_assert ( !(o3 < val), "" ); // equal
|
||||
static_assert ( (o3 < T(3)), "" );
|
||||
|
||||
static_assert ( !(T(1) < o1), "" );
|
||||
static_assert ( !(T(1) < o2), "" ); // equal
|
||||
static_assert ( (T(1) < o3), "" );
|
||||
static_assert ( !(val < o2), "" );
|
||||
static_assert ( !(val < o3), "" ); // equal
|
||||
static_assert ( !(T(3) < o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
// template <class T> constexpr bool operator!=(const optional<T>& x, const T& v);
|
||||
// template <class T> constexpr bool operator!=(const T& v, const optional<T>& x);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator == ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ == rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr T val(2);
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
constexpr O o3{val}; // engaged
|
||||
|
||||
static_assert ( (o1 != T(1)), "" );
|
||||
static_assert ( !(o2 != T(1)), "" );
|
||||
static_assert ( (o3 != T(1)), "" );
|
||||
static_assert ( !(o3 != T(2)), "" );
|
||||
static_assert ( !(o3 != val), "" );
|
||||
|
||||
static_assert ( (T(1) != o1), "" );
|
||||
static_assert ( !(T(1) != o2), "" );
|
||||
static_assert ( (T(1) != o3), "" );
|
||||
static_assert ( !(T(2) != o3), "" );
|
||||
static_assert ( !(val != o3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
47
test/std/experimental/optional/optional.hash/hash.pass.cpp
Normal file
47
test/std/experimental/optional/optional.hash/hash.pass.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> struct hash<optional<T>>;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
optional<T> opt;
|
||||
assert(std::hash<optional<T>>{}(opt) == 0);
|
||||
opt = 2;
|
||||
assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
|
||||
}
|
||||
{
|
||||
typedef std::string T;
|
||||
optional<T> opt;
|
||||
assert(std::hash<optional<T>>{}(opt) == 0);
|
||||
opt = std::string("123");
|
||||
assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int> T;
|
||||
optional<T> opt;
|
||||
assert(std::hash<optional<T>>{}(opt) == 0);
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// struct in_place_t{};
|
||||
// constexpr in_place_t in_place{};
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
|
||||
constexpr
|
||||
int
|
||||
test(const in_place_t&)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
static_assert((std::is_class<in_place_t>::value), "");
|
||||
static_assert((std::is_empty<in_place_t>::value), "");
|
||||
|
||||
static_assert(test(in_place) == 3, "");
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( (nullopt == o1), "" );
|
||||
static_assert ( !(nullopt == o2), "" );
|
||||
static_assert ( (o1 == nullopt), "" );
|
||||
static_assert ( !(o2 == nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt == o1), "");
|
||||
static_assert (noexcept(o1 == nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator>(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( !(nullopt > o1), "" );
|
||||
static_assert ( !(nullopt > o2), "" );
|
||||
static_assert ( !(o1 > nullopt), "" );
|
||||
static_assert ( (o2 > nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt > o1), "");
|
||||
static_assert (noexcept(o1 > nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator>=(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( (nullopt >= o1), "" );
|
||||
static_assert ( !(nullopt >= o2), "" );
|
||||
static_assert ( (o1 >= nullopt), "" );
|
||||
static_assert ( (o2 >= nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt >= o1), "");
|
||||
static_assert (noexcept(o1 >= nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator<=(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( (nullopt <= o1), "" );
|
||||
static_assert ( (nullopt <= o2), "" );
|
||||
static_assert ( (o1 <= nullopt), "" );
|
||||
static_assert ( !(o2 <= nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt <= o1), "");
|
||||
static_assert (noexcept(o1 <= nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator<(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( !(nullopt < o1), "" );
|
||||
static_assert ( (nullopt < o2), "" );
|
||||
static_assert ( !(o1 < nullopt), "" );
|
||||
static_assert ( !(o2 < nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt < o1), "");
|
||||
static_assert (noexcept(o1 < nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept;
|
||||
// template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2{1}; // engaged
|
||||
|
||||
static_assert ( !(nullopt != o1), "" );
|
||||
static_assert ( (nullopt != o2), "" );
|
||||
static_assert ( !(o1 != nullopt), "" );
|
||||
static_assert ( (o2 != nullopt), "" );
|
||||
|
||||
static_assert (noexcept(nullopt != o1), "");
|
||||
static_assert (noexcept(o1 != nullopt), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// struct nullopt_t{see below};
|
||||
// constexpr nullopt_t nullopt(unspecified);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
constexpr
|
||||
int
|
||||
test(const nullopt_t&)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
static_assert((std::is_class<nullopt_t>::value), "");
|
||||
static_assert((std::is_empty<nullopt_t>::value), "");
|
||||
static_assert((std::is_literal_type<nullopt_t>::value), "");
|
||||
static_assert((!std::is_default_constructible<nullopt_t>::value), "");
|
||||
|
||||
static_assert(test(nullopt) == 3, "");
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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> optional<T>& operator=(U&& v);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
static_assert(std::is_assignable<optional<int>, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<const optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<optional<int>, X>::value, "");
|
||||
{
|
||||
optional<int> opt;
|
||||
opt = 1;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
optional<std::unique_ptr<int>> opt;
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
}
|
||||
{
|
||||
optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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<T>& operator=(const optional<T>& rhs);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
|
||||
X() = default;
|
||||
X(const X&)
|
||||
{
|
||||
if (throw_now)
|
||||
throw 6;
|
||||
}
|
||||
};
|
||||
|
||||
bool X::throw_now = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
X::throw_now = true;
|
||||
opt = opt2;
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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... Args> void optional<T>::emplace(Args&&... args);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
X() : i_(0) {}
|
||||
X(int i) : i_(i) {}
|
||||
X(int i, int j) : i_(i), j_(j) {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
public:
|
||||
static bool dtor_called;
|
||||
Y() = default;
|
||||
~Y() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool Y::dtor_called = false;
|
||||
|
||||
class Z
|
||||
{
|
||||
public:
|
||||
static bool dtor_called;
|
||||
Z() = default;
|
||||
Z(int) {throw 6;}
|
||||
~Z() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool Z::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt(2);
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<int> opt(2);
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
}
|
||||
{
|
||||
Y y;
|
||||
{
|
||||
optional<Y> opt(y);
|
||||
assert(Y::dtor_called == false);
|
||||
opt.emplace();
|
||||
assert(Y::dtor_called == true);
|
||||
}
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(Z::dtor_called == false);
|
||||
opt.emplace(1);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
assert(Z::dtor_called == true);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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, class... Args>
|
||||
// void optional<T>::emplace(initializer_list<U> il, Args&&... args);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
static bool dtor_called;
|
||||
constexpr X() : i_(0) {}
|
||||
constexpr X(int i) : i_(i) {}
|
||||
constexpr X(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
|
||||
~X() {dtor_called = true;}
|
||||
|
||||
friend constexpr bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
bool X::dtor_called = false;
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
constexpr Y() : i_(0) {}
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
constexpr Y(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
static bool dtor_called;
|
||||
constexpr Z() : i_(0) {}
|
||||
constexpr Z(int i) : i_(i) {}
|
||||
constexpr Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
|
||||
{throw 6;}
|
||||
~Z() {dtor_called = true;}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
bool Z::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
X x;
|
||||
{
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt.emplace({1, 2});
|
||||
assert(X::dtor_called == true);
|
||||
assert(*opt == X({1, 2}));
|
||||
}
|
||||
}
|
||||
{
|
||||
optional<std::vector<int>> opt;
|
||||
opt.emplace({1, 2, 3}, std::allocator<int>());
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == std::vector<int>({1, 2, 3}));
|
||||
}
|
||||
{
|
||||
optional<Y> opt;
|
||||
opt.emplace({1, 2});
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == Y({1, 2}));
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(Z::dtor_called == false);
|
||||
opt.emplace({1, 2});
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
assert(Z::dtor_called == true);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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<T>& operator=(optional<T>&& rhs)
|
||||
// noexcept(is_nothrow_move_assignable<T>::value &&
|
||||
// is_nothrow_move_constructible<T>::value);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
|
||||
X() = default;
|
||||
X(X&&)
|
||||
{
|
||||
if (throw_now)
|
||||
throw 6;
|
||||
}
|
||||
X& operator=(X&&) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct Y {};
|
||||
|
||||
bool X::throw_now = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<optional<int>>::value, "");
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
X::throw_now = true;
|
||||
opt = std::move(opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, "");
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
// optional<T>& operator=(nullopt_t) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool dtor_called;
|
||||
~X() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool X::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
assert(X::dtor_called == false);
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == false);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
X x;
|
||||
{
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == true);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 optional(const T& v);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
X(int i) : i_(i) {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(const Z&) {throw 6;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef int T;
|
||||
constexpr T t(5);
|
||||
constexpr optional<T> opt(t);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 5, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(const T&) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
typedef double T;
|
||||
constexpr T t(3);
|
||||
constexpr optional<T> opt(t);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 3, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(const T&) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
const T t(3);
|
||||
optional<T> opt(t);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 3);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
constexpr T t(3);
|
||||
constexpr optional<T> opt(t);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 3, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(const T&) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
try
|
||||
{
|
||||
const T t(3);
|
||||
optional<T> opt(t);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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(const optional<T>& rhs);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
template <class T>
|
||||
void
|
||||
test(const optional<T>& rhs, bool is_going_to_throw = false)
|
||||
{
|
||||
bool rhs_engaged = static_cast<bool>(rhs);
|
||||
try
|
||||
{
|
||||
optional<T> lhs = rhs;
|
||||
assert(is_going_to_throw == false);
|
||||
assert(static_cast<bool>(lhs) == rhs_engaged);
|
||||
if (rhs_engaged)
|
||||
assert(*lhs == *rhs);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
}
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
X(int i) : i_(i) {}
|
||||
X(const X& x) : i_(x.i_) {}
|
||||
~X() {i_ = 0;}
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Y(int i) : i_(i) {}
|
||||
Y(const Y& x) : i_(x.i_) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
int count = 0;
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(const Z&)
|
||||
{
|
||||
if (++count == 2)
|
||||
throw 6;
|
||||
}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef int T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
optional<T> rhs(3);
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
optional<T> rhs(X(3));
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
optional<T> rhs(Y(3));
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
optional<T> rhs(Z(3));
|
||||
test(rhs, true);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -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 optional() noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
template <class Opt>
|
||||
void
|
||||
test_constexpr()
|
||||
{
|
||||
static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
|
||||
constexpr Opt opt;
|
||||
static_assert(static_cast<bool>(opt) == false, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public Opt
|
||||
{
|
||||
constexpr test_constexpr_ctor() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class Opt>
|
||||
void
|
||||
test()
|
||||
{
|
||||
static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
|
||||
Opt opt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public Opt
|
||||
{
|
||||
constexpr test_constexpr_ctor() {}
|
||||
};
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
X();
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
test_constexpr<optional<int>>();
|
||||
test_constexpr<optional<int*>>();
|
||||
test<optional<X>>();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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... Args>
|
||||
// constexpr explicit optional(in_place_t, Args&&... args);
|
||||
|
||||
#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;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
X() : i_(0) {}
|
||||
X(int i) : i_(i) {}
|
||||
X(int i, int j) : i_(i), j_(j) {}
|
||||
|
||||
~X() {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
constexpr Y() : i_(0) {}
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
constexpr Y(int i, int j) : i_(i), j_(j) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {throw 6;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<int> opt(in_place, 5);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 5, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<int>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t, int i)
|
||||
: optional<int>(in_place, i) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place, 5);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(5));
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place, 5, 4);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(5, 4));
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(in_place);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == Y(), "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<Y>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t)
|
||||
: optional<Y>(in_place) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(in_place, 5);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == Y(5), "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<Y>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t, int i)
|
||||
: optional<Y>(in_place, i) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(in_place, 5, 4);
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == Y(5, 4), "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<Y>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t, int i, int j)
|
||||
: optional<Y>(in_place, i, j) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
const optional<Z> opt(in_place, 1);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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, class... Args>
|
||||
// constexpr
|
||||
// explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
X() : i_(0) {}
|
||||
X(int i) : i_(i) {}
|
||||
X(int i, int j) : i_(i), j_(j) {}
|
||||
|
||||
~X() {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
constexpr Y() : i_(0) {}
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
constexpr Y(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
constexpr Z() : i_(0) {}
|
||||
constexpr Z(int i) : i_(i) {}
|
||||
constexpr Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
|
||||
{throw 6;}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
static_assert(!std::is_constructible<X, std::initializer_list<int>&>::value, "");
|
||||
static_assert(!std::is_constructible<optional<X>, std::initializer_list<int>&>::value, "");
|
||||
}
|
||||
{
|
||||
optional<std::vector<int>> opt(in_place, {3, 1});
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert((*opt == std::vector<int>{3, 1}));
|
||||
assert(opt->size() == 2);
|
||||
}
|
||||
{
|
||||
optional<std::vector<int>> opt(in_place, {3, 1}, std::allocator<int>());
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert((*opt == std::vector<int>{3, 1}));
|
||||
assert(opt->size() == 2);
|
||||
}
|
||||
{
|
||||
static_assert(std::is_constructible<optional<Y>, std::initializer_list<int>&>::value, "");
|
||||
constexpr optional<Y> opt(in_place, {3, 1});
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == Y{3, 1}, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<Y>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t, std::initializer_list<int> i)
|
||||
: optional<Y>(in_place, i) {}
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
static_assert(std::is_constructible<optional<Z>, std::initializer_list<int>&>::value, "");
|
||||
try
|
||||
{
|
||||
optional<Z> opt(in_place, {3, 1});
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<Z>
|
||||
{
|
||||
constexpr test_constexpr_ctor(in_place_t, std::initializer_list<int> i)
|
||||
: optional<Z>(in_place, i) {}
|
||||
};
|
||||
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
template <class T>
|
||||
void
|
||||
test(optional<T>& rhs, bool is_going_to_throw = false)
|
||||
{
|
||||
static_assert(std::is_nothrow_move_constructible<optional<T>>::value ==
|
||||
std::is_nothrow_move_constructible<T>::value, "");
|
||||
bool rhs_engaged = static_cast<bool>(rhs);
|
||||
try
|
||||
{
|
||||
optional<T> lhs = std::move(rhs);
|
||||
assert(is_going_to_throw == false);
|
||||
assert(static_cast<bool>(lhs) == rhs_engaged);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
}
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
X(int i) : i_(i) {}
|
||||
X(X&& x) : i_(x.i_) {x.i_ = 0;}
|
||||
~X() {i_ = 0;}
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Y(int i) : i_(i) {}
|
||||
Y(Y&& x) noexcept : i_(x.i_) {x.i_ = 0;}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
int count = 0;
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(Z&&)
|
||||
{
|
||||
if (++count == 2)
|
||||
throw 6;
|
||||
}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef int T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
optional<T> rhs(3);
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
optional<T> rhs(X(3));
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
optional<T> rhs(Y(3));
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
optional<T> rhs;
|
||||
test(rhs);
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
optional<T> rhs(Z(3));
|
||||
test(rhs, true);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 optional(nullopt_t) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
template <class Opt>
|
||||
void
|
||||
test_constexpr()
|
||||
{
|
||||
static_assert(noexcept(Opt(nullopt)), "");
|
||||
constexpr Opt opt(nullopt);
|
||||
static_assert(static_cast<bool>(opt) == false, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public Opt
|
||||
{
|
||||
constexpr test_constexpr_ctor() {}
|
||||
};
|
||||
}
|
||||
|
||||
template <class Opt>
|
||||
void
|
||||
test()
|
||||
{
|
||||
static_assert(noexcept(Opt(nullopt)), "");
|
||||
Opt opt(nullopt);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public Opt
|
||||
{
|
||||
constexpr test_constexpr_ctor() {}
|
||||
};
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
X();
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
test_constexpr<optional<int>>();
|
||||
test_constexpr<optional<int*>>();
|
||||
test<optional<X>>();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 optional(T&& v);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
X(int i) : i_(i) {}
|
||||
X(X&& x) : i_(x.i_) {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
constexpr Y(Y&& x) : i_(x.i_) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(Z&&) {throw 6;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef int T;
|
||||
constexpr optional<T> opt(T(5));
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 5, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(T&&) {}
|
||||
};
|
||||
}
|
||||
{
|
||||
typedef double T;
|
||||
constexpr optional<T> opt(T(3));
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 3, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(T&&) {}
|
||||
};
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
optional<T> opt(T(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 3);
|
||||
}
|
||||
{
|
||||
typedef Y T;
|
||||
constexpr optional<T> opt(T(3));
|
||||
static_assert(static_cast<bool>(opt) == true, "");
|
||||
static_assert(*opt == 3, "");
|
||||
|
||||
struct test_constexpr_ctor
|
||||
: public optional<T>
|
||||
{
|
||||
constexpr test_constexpr_ctor(T&&) {}
|
||||
};
|
||||
}
|
||||
{
|
||||
typedef Z T;
|
||||
try
|
||||
{
|
||||
optional<T> opt(T(3));
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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();
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
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, "");
|
||||
static_assert(std::is_trivially_destructible<optional<T>>::value, "");
|
||||
}
|
||||
{
|
||||
typedef double T;
|
||||
static_assert(std::is_trivially_destructible<T>::value, "");
|
||||
static_assert(std::is_trivially_destructible<optional<T>>::value, "");
|
||||
}
|
||||
{
|
||||
typedef X T;
|
||||
static_assert(!std::is_trivially_destructible<T>::value, "");
|
||||
static_assert(!std::is_trivially_destructible<optional<T>>::value, "");
|
||||
{
|
||||
X x;
|
||||
optional<X> opt{x};
|
||||
assert(X::dtor_called == false);
|
||||
}
|
||||
assert(X::dtor_called == true);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
constexpr int test() const {return 3;}
|
||||
#else
|
||||
constexpr int test() {return 3;}
|
||||
#endif
|
||||
};
|
||||
|
||||
#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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// void swap(optional&)
|
||||
// noexcept(is_nothrow_move_constructible<T>::value &&
|
||||
// noexcept(swap(declval<T&>(), declval<T&>())));
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
static unsigned dtor_called;
|
||||
X(int i) : i_(i) {}
|
||||
X(X&& x) = default;
|
||||
X& operator=(X&&) = default;
|
||||
~X() {++dtor_called;}
|
||||
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
unsigned X::dtor_called = 0;
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
static unsigned dtor_called;
|
||||
Y(int i) : i_(i) {}
|
||||
Y(Y&&) = default;
|
||||
~Y() {++dtor_called;}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
friend void swap(Y& x, Y& y) {std::swap(x.i_, y.i_);}
|
||||
};
|
||||
|
||||
unsigned Y::dtor_called = 0;
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(Z&&) {throw 7;}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
|
||||
friend void swap(Z& x, Z& y) {throw 6;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt1;
|
||||
optional<int> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt1(1);
|
||||
optional<int> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt1;
|
||||
optional<int> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt1(1);
|
||||
optional<int> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt1;
|
||||
optional<X> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
assert(X::dtor_called == 0);
|
||||
}
|
||||
{
|
||||
optional<X> opt1(1);
|
||||
optional<X> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
X::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(X::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt1;
|
||||
optional<X> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
X::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(X::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<X> opt1(1);
|
||||
optional<X> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
X::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(X::dtor_called == 1); // from inside std::swap
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1;
|
||||
optional<Y> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
assert(Y::dtor_called == 0);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1(1);
|
||||
optional<Y> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
Y::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(Y::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1;
|
||||
optional<Y> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
Y::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(Y::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1(1);
|
||||
optional<Y> opt2(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
Y::dtor_called = 0;
|
||||
opt1.swap(opt2);
|
||||
assert(Y::dtor_called == 0);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
optional<Z> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
opt1.swap(opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
opt1.emplace(1);
|
||||
optional<Z> opt2;
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
try
|
||||
{
|
||||
opt1.swap(opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 7);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
optional<Z> opt2;
|
||||
opt2.emplace(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
try
|
||||
{
|
||||
opt1.swap(opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 7);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
opt1.emplace(1);
|
||||
optional<Z> opt2;
|
||||
opt2.emplace(2);
|
||||
static_assert(noexcept(opt1.swap(opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
try
|
||||
{
|
||||
opt1.swap(opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 shall be an object type and shall satisfy the requirements of Destructible
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
optional<const void> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 shall be an object type and shall satisfy the requirements of Destructible
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
private:
|
||||
~X() {}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
optional<X> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 shall be an object type and shall satisfy the requirements of Destructible
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
~X() noexcept(false) {}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
optional<X> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 shall be an object type and shall satisfy the requirements of Destructible
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
optional<void> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T>
|
||||
// class optional
|
||||
// {
|
||||
// public:
|
||||
// typedef T value_type;
|
||||
// ...
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
template <class Opt, class T>
|
||||
void
|
||||
test()
|
||||
{
|
||||
static_assert(std::is_same<typename Opt::value_type, T>::value, "");
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
test<optional<int>, int>();
|
||||
test<optional<const int>, const int>();
|
||||
test<optional<double>, double>();
|
||||
test<optional<const double>, const double>();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator==(const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator == ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ == rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( o1 == o1 , "" );
|
||||
static_assert ( o1 == o2 , "" );
|
||||
static_assert ( !(o1 == o3), "" );
|
||||
static_assert ( !(o1 == o4), "" );
|
||||
static_assert ( !(o1 == o5), "" );
|
||||
|
||||
static_assert ( o2 == o1 , "" );
|
||||
static_assert ( o2 == o2 , "" );
|
||||
static_assert ( !(o2 == o3), "" );
|
||||
static_assert ( !(o2 == o4), "" );
|
||||
static_assert ( !(o2 == o5), "" );
|
||||
|
||||
static_assert ( !(o3 == o1), "" );
|
||||
static_assert ( !(o3 == o2), "" );
|
||||
static_assert ( o3 == o3 , "" );
|
||||
static_assert ( !(o3 == o4), "" );
|
||||
static_assert ( o3 == o5 , "" );
|
||||
|
||||
static_assert ( !(o4 == o1), "" );
|
||||
static_assert ( !(o4 == o2), "" );
|
||||
static_assert ( !(o4 == o3), "" );
|
||||
static_assert ( o4 == o4 , "" );
|
||||
static_assert ( !(o4 == o5), "" );
|
||||
|
||||
static_assert ( !(o5 == o1), "" );
|
||||
static_assert ( !(o5 == o2), "" );
|
||||
static_assert ( o5 == o3 , "" );
|
||||
static_assert ( !(o5 == o4), "" );
|
||||
static_assert ( o5 == o5 , "" );
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator>= (const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef optional<X> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( (o1 >= o1), "" );
|
||||
static_assert ( (o1 >= o2), "" );
|
||||
static_assert ( !(o1 >= o3), "" );
|
||||
static_assert ( !(o1 >= o4), "" );
|
||||
static_assert ( !(o1 >= o5), "" );
|
||||
|
||||
static_assert ( (o2 >= o1), "" );
|
||||
static_assert ( (o2 >= o2), "" );
|
||||
static_assert ( !(o2 >= o3), "" );
|
||||
static_assert ( !(o2 >= o4), "" );
|
||||
static_assert ( !(o2 >= o5), "" );
|
||||
|
||||
static_assert ( (o3 >= o1), "" );
|
||||
static_assert ( (o3 >= o2), "" );
|
||||
static_assert ( (o3 >= o3), "" );
|
||||
static_assert ( !(o3 >= o4), "" );
|
||||
static_assert ( (o3 >= o5), "" );
|
||||
|
||||
static_assert ( (o4 >= o1), "" );
|
||||
static_assert ( (o4 >= o2), "" );
|
||||
static_assert ( (o4 >= o3), "" );
|
||||
static_assert ( (o4 >= o4), "" );
|
||||
static_assert ( (o4 >= o5), "" );
|
||||
|
||||
static_assert ( (o5 >= o1), "" );
|
||||
static_assert ( (o5 >= o2), "" );
|
||||
static_assert ( (o5 >= o3), "" );
|
||||
static_assert ( !(o5 >= o4), "" );
|
||||
static_assert ( (o5 >= o5), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator> (const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef optional<X> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( !(o1 > o1), "" );
|
||||
static_assert ( !(o1 > o2), "" );
|
||||
static_assert ( !(o1 > o3), "" );
|
||||
static_assert ( !(o1 > o4), "" );
|
||||
static_assert ( !(o1 > o5), "" );
|
||||
|
||||
static_assert ( !(o2 > o1), "" );
|
||||
static_assert ( !(o2 > o2), "" );
|
||||
static_assert ( !(o2 > o3), "" );
|
||||
static_assert ( !(o2 > o4), "" );
|
||||
static_assert ( !(o2 > o5), "" );
|
||||
|
||||
static_assert ( (o3 > o1), "" );
|
||||
static_assert ( (o3 > o2), "" );
|
||||
static_assert ( !(o3 > o3), "" );
|
||||
static_assert ( !(o3 > o4), "" );
|
||||
static_assert ( !(o3 > o5), "" );
|
||||
|
||||
static_assert ( (o4 > o1), "" );
|
||||
static_assert ( (o4 > o2), "" );
|
||||
static_assert ( (o4 > o3), "" );
|
||||
static_assert ( !(o4 > o4), "" );
|
||||
static_assert ( (o4 > o5), "" );
|
||||
|
||||
static_assert ( (o5 > o1), "" );
|
||||
static_assert ( (o5 > o2), "" );
|
||||
static_assert ( !(o5 > o3), "" );
|
||||
static_assert ( !(o5 > o4), "" );
|
||||
static_assert ( !(o5 > o5), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator<= (const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef optional<X> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( (o1 <= o1), "" );
|
||||
static_assert ( (o1 <= o2), "" );
|
||||
static_assert ( (o1 <= o3), "" );
|
||||
static_assert ( (o1 <= o4), "" );
|
||||
static_assert ( (o1 <= o5), "" );
|
||||
|
||||
static_assert ( (o2 <= o1), "" );
|
||||
static_assert ( (o2 <= o2), "" );
|
||||
static_assert ( (o2 <= o3), "" );
|
||||
static_assert ( (o2 <= o4), "" );
|
||||
static_assert ( (o2 <= o5), "" );
|
||||
|
||||
static_assert ( !(o3 <= o1), "" );
|
||||
static_assert ( !(o3 <= o2), "" );
|
||||
static_assert ( (o3 <= o3), "" );
|
||||
static_assert ( (o3 <= o4), "" );
|
||||
static_assert ( (o3 <= o5), "" );
|
||||
|
||||
static_assert ( !(o4 <= o1), "" );
|
||||
static_assert ( !(o4 <= o2), "" );
|
||||
static_assert ( !(o4 <= o3), "" );
|
||||
static_assert ( (o4 <= o4), "" );
|
||||
static_assert ( !(o4 <= o5), "" );
|
||||
|
||||
static_assert ( !(o5 <= o1), "" );
|
||||
static_assert ( !(o5 <= o2), "" );
|
||||
static_assert ( (o5 <= o3), "" );
|
||||
static_assert ( (o5 <= o4), "" );
|
||||
static_assert ( (o5 <= o5), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator< (const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator < ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ < rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef optional<X> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( !(o1 < o1), "" );
|
||||
static_assert ( !(o1 < o2), "" );
|
||||
static_assert ( (o1 < o3), "" );
|
||||
static_assert ( (o1 < o4), "" );
|
||||
static_assert ( (o1 < o5), "" );
|
||||
|
||||
static_assert ( !(o2 < o1), "" );
|
||||
static_assert ( !(o2 < o2), "" );
|
||||
static_assert ( (o2 < o3), "" );
|
||||
static_assert ( (o2 < o4), "" );
|
||||
static_assert ( (o2 < o5), "" );
|
||||
|
||||
static_assert ( !(o3 < o1), "" );
|
||||
static_assert ( !(o3 < o2), "" );
|
||||
static_assert ( !(o3 < o3), "" );
|
||||
static_assert ( (o3 < o4), "" );
|
||||
static_assert ( !(o3 < o5), "" );
|
||||
|
||||
static_assert ( !(o4 < o1), "" );
|
||||
static_assert ( !(o4 < o2), "" );
|
||||
static_assert ( !(o4 < o3), "" );
|
||||
static_assert ( !(o4 < o4), "" );
|
||||
static_assert ( !(o4 < o5), "" );
|
||||
|
||||
static_assert ( !(o5 < o1), "" );
|
||||
static_assert ( !(o5 < o2), "" );
|
||||
static_assert ( !(o5 < o3), "" );
|
||||
static_assert ( (o5 < o4), "" );
|
||||
static_assert ( !(o5 < o5), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> constexpr bool operator!=(const optional<T>& x, const optional<T>& y);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
constexpr bool operator == ( const X &lhs, const X &rhs )
|
||||
{ return lhs.i_ == rhs.i_ ; }
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef X T;
|
||||
typedef optional<T> O;
|
||||
|
||||
constexpr O o1; // disengaged
|
||||
constexpr O o2; // disengaged
|
||||
constexpr O o3{1}; // engaged
|
||||
constexpr O o4{2}; // engaged
|
||||
constexpr O o5{1}; // engaged
|
||||
|
||||
static_assert ( !(o1 != o1), "" );
|
||||
static_assert ( !(o1 != o2), "" );
|
||||
static_assert ( (o1 != o3), "" );
|
||||
static_assert ( (o1 != o4), "" );
|
||||
static_assert ( (o1 != o5), "" );
|
||||
|
||||
static_assert ( !(o2 != o1), "" );
|
||||
static_assert ( !(o2 != o2), "" );
|
||||
static_assert ( (o2 != o3), "" );
|
||||
static_assert ( (o2 != o4), "" );
|
||||
static_assert ( (o2 != o5), "" );
|
||||
|
||||
static_assert ( (o3 != o1), "" );
|
||||
static_assert ( (o3 != o2), "" );
|
||||
static_assert ( !(o3 != o3), "" );
|
||||
static_assert ( (o3 != o4), "" );
|
||||
static_assert ( !(o3 != o5), "" );
|
||||
|
||||
static_assert ( (o4 != o1), "" );
|
||||
static_assert ( (o4 != o2), "" );
|
||||
static_assert ( (o4 != o3), "" );
|
||||
static_assert ( !(o4 != o4), "" );
|
||||
static_assert ( (o4 != o5), "" );
|
||||
|
||||
static_assert ( (o5 != o1), "" );
|
||||
static_assert ( (o5 != o2), "" );
|
||||
static_assert ( !(o5 != o3), "" );
|
||||
static_assert ( (o5 != o4), "" );
|
||||
static_assert ( !(o5 != o5), "" );
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T>
|
||||
// constexpr
|
||||
// optional<typename decay<T>::type>
|
||||
// make_optional(T&& v);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::make_optional;
|
||||
|
||||
{
|
||||
optional<int> opt = make_optional(2);
|
||||
assert(*opt == 2);
|
||||
}
|
||||
{
|
||||
std::string s("123");
|
||||
optional<std::string> opt = make_optional(s);
|
||||
assert(*opt == s);
|
||||
}
|
||||
{
|
||||
std::string s("123");
|
||||
optional<std::string> opt = make_optional(std::move(s));
|
||||
assert(*opt == "123");
|
||||
assert(s.empty());
|
||||
}
|
||||
{
|
||||
std::unique_ptr<int> s(new int(3));
|
||||
optional<std::unique_ptr<int>> opt = make_optional(std::move(s));
|
||||
assert(**opt == 3);
|
||||
assert(s == nullptr);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
305
test/std/experimental/optional/optional.specalg/swap.pass.cpp
Normal file
305
test/std/experimental/optional/optional.specalg/swap.pass.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> void swap(optional<T>& x, optional<T>& y)
|
||||
// noexcept(noexcept(x.swap(y)));
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
static unsigned dtor_called;
|
||||
X(int i) : i_(i) {}
|
||||
X(X&& x) = default;
|
||||
X& operator=(X&&) = default;
|
||||
~X() {++dtor_called;}
|
||||
|
||||
friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
unsigned X::dtor_called = 0;
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
static unsigned dtor_called;
|
||||
Y(int i) : i_(i) {}
|
||||
Y(Y&&) = default;
|
||||
~Y() {++dtor_called;}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
|
||||
friend void swap(Y& x, Y& y) {std::swap(x.i_, y.i_);}
|
||||
};
|
||||
|
||||
unsigned Y::dtor_called = 0;
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
public:
|
||||
Z(int i) : i_(i) {}
|
||||
Z(Z&&) {throw 7;}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
|
||||
friend void swap(Z& x, Z& y) {throw 6;}
|
||||
};
|
||||
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt1;
|
||||
optional<int> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt1(1);
|
||||
optional<int> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt1;
|
||||
optional<int> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt1(1);
|
||||
optional<int> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt1;
|
||||
optional<X> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
assert(X::dtor_called == 0);
|
||||
}
|
||||
{
|
||||
optional<X> opt1(1);
|
||||
optional<X> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
X::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(X::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt1;
|
||||
optional<X> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
X::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(X::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<X> opt1(1);
|
||||
optional<X> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == true, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
X::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(X::dtor_called == 1); // from inside std::swap
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1;
|
||||
optional<Y> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
assert(Y::dtor_called == 0);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1(1);
|
||||
optional<Y> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
Y::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(Y::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1;
|
||||
optional<Y> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
Y::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(Y::dtor_called == 1);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Y> opt1(1);
|
||||
optional<Y> opt2(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
Y::dtor_called = 0;
|
||||
swap(opt1, opt2);
|
||||
assert(Y::dtor_called == 0);
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 2);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 1);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
optional<Z> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
swap(opt1, opt2);
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
opt1.emplace(1);
|
||||
optional<Z> opt2;
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
try
|
||||
{
|
||||
swap(opt1, opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 7);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == false);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
optional<Z> opt2;
|
||||
opt2.emplace(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
try
|
||||
{
|
||||
swap(opt1, opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 7);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == false);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
}
|
||||
{
|
||||
optional<Z> opt1;
|
||||
opt1.emplace(1);
|
||||
optional<Z> opt2;
|
||||
opt2.emplace(2);
|
||||
static_assert(noexcept(swap(opt1, opt2)) == false, "");
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
try
|
||||
{
|
||||
swap(opt1, opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
}
|
||||
assert(static_cast<bool>(opt1) == true);
|
||||
assert(*opt1 == 1);
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
assert(*opt2 == 2);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for
|
||||
// (possibly cv-qualified) in_place_t is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
|
||||
optional<const in_place_t> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for a
|
||||
// reference type is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
optional<const int&> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for
|
||||
// (possibly cv-qualified) null_opt_t is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
optional<const nullopt_t> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for
|
||||
// (possibly cv-qualified) in_place_t is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
|
||||
optional<in_place_t> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// #include <initializer_list>
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
std::initializer_list<int> list;
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for a
|
||||
// reference type is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
optional<int&> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for
|
||||
// (possibly cv-qualified) null_opt_t is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
optional<nullopt_t> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// A program that necessitates the instantiation of template optional for a
|
||||
// reference type is ill-formed.
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
optional<int&&> opt;
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
20
test/std/experimental/optional/version.pass.cpp
Normal file
20
test/std/experimental/optional/version.pass.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#ifndef _LIBCPP_VERSION
|
||||
#error _LIBCPP_VERSION not defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
12
test/std/experimental/string.view/nothing_to_do.pass.cpp
Normal file
12
test/std/experimental/string.view/nothing_to_do.pass.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <experimental/string_view>
|
||||
|
||||
int main () {}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// NOTE: Older versions of clang have a bug where they fail to evalute
|
||||
// string_view::at as a constant expression.
|
||||
// XFAIL: apple-clang-6.0, clang-3.4, clang-3.3
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr const _CharT& at(size_type _pos) const;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <typename CharT>
|
||||
void test ( const CharT *s, size_t len ) {
|
||||
std::experimental::basic_string_view<CharT> sv ( s, len );
|
||||
assert ( sv.length() == len );
|
||||
for ( size_t i = 0; i < len; ++i ) {
|
||||
assert ( sv.at(i) == s[i] );
|
||||
assert ( &sv.at(i) == s + i );
|
||||
}
|
||||
|
||||
try { sv.at(len); } catch ( const std::out_of_range & ) { return ; }
|
||||
assert ( false );
|
||||
}
|
||||
|
||||
int main () {
|
||||
test ( "ABCDE", 5 );
|
||||
test ( "a", 1 );
|
||||
|
||||
test ( L"ABCDE", 5 );
|
||||
test ( L"a", 1 );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( u"ABCDE", 5 );
|
||||
test ( u"a", 1 );
|
||||
|
||||
test ( U"ABCDE", 5 );
|
||||
test ( U"a", 1 );
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
||||
static_assert ( sv.length() == 2, "" );
|
||||
static_assert ( sv.at(0) == 'A', "" );
|
||||
static_assert ( sv.at(1) == 'B', "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr const _CharT& front();
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <typename CharT>
|
||||
bool test ( const CharT *s, size_t len ) {
|
||||
std::experimental::basic_string_view<CharT> sv ( s, len );
|
||||
assert ( sv.length() == len );
|
||||
assert ( sv.back() == s[len-1] );
|
||||
return &sv.back() == s + len - 1;
|
||||
}
|
||||
|
||||
int main () {
|
||||
assert ( test ( "ABCDE", 5 ));
|
||||
assert ( test ( "a", 1 ));
|
||||
|
||||
assert ( test ( L"ABCDE", 5 ));
|
||||
assert ( test ( L"a", 1 ));
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
assert ( test ( u"ABCDE", 5 ));
|
||||
assert ( test ( u"a", 1 ));
|
||||
|
||||
assert ( test ( U"ABCDE", 5 ));
|
||||
assert ( test ( U"a", 1 ));
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
||||
static_assert ( sv.length() == 2, "" );
|
||||
static_assert ( sv.back() == 'B', "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr const _CharT* data() const noexcept;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <typename CharT>
|
||||
void test ( const CharT *s, size_t len ) {
|
||||
std::experimental::basic_string_view<CharT> sv ( s, len );
|
||||
assert ( sv.length() == len );
|
||||
assert ( sv.data() == s );
|
||||
}
|
||||
|
||||
int main () {
|
||||
test ( "ABCDE", 5 );
|
||||
test ( "a", 1 );
|
||||
|
||||
test ( L"ABCDE", 5 );
|
||||
test ( L"a", 1 );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( u"ABCDE", 5 );
|
||||
test ( u"a", 1 );
|
||||
|
||||
test ( U"ABCDE", 5 );
|
||||
test ( U"a", 1 );
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr const char *s = "ABC";
|
||||
constexpr std::experimental::basic_string_view<char> sv( s, 2 );
|
||||
static_assert( sv.length() == 2, "" );
|
||||
static_assert( sv.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr const _CharT& back();
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <typename CharT>
|
||||
bool test ( const CharT *s, size_t len ) {
|
||||
std::experimental::basic_string_view<CharT> sv ( s, len );
|
||||
assert ( sv.length() == len );
|
||||
assert ( sv.front() == s[0] );
|
||||
return &sv.front() == s;
|
||||
}
|
||||
|
||||
int main () {
|
||||
assert ( test ( "ABCDE", 5 ));
|
||||
assert ( test ( "a", 1 ));
|
||||
|
||||
assert ( test ( L"ABCDE", 5 ));
|
||||
assert ( test ( L"a", 1 ));
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
assert ( test ( u"ABCDE", 5 ));
|
||||
assert ( test ( u"a", 1 ));
|
||||
|
||||
assert ( test ( U"ABCDE", 5 ));
|
||||
assert ( test ( U"a", 1 ));
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
||||
static_assert ( sv.length() == 2, "" );
|
||||
static_assert ( sv.front() == 'A', "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr const _CharT& operator[](size_type _pos) const;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <typename CharT>
|
||||
void test ( const CharT *s, size_t len ) {
|
||||
std::experimental::basic_string_view<CharT> sv ( s, len );
|
||||
assert ( sv.length() == len );
|
||||
for ( size_t i = 0; i < len; ++i ) {
|
||||
assert ( sv[i] == s[i] );
|
||||
assert ( &sv[i] == s + i );
|
||||
}
|
||||
}
|
||||
|
||||
int main () {
|
||||
test ( "ABCDE", 5 );
|
||||
test ( "a", 1 );
|
||||
|
||||
test ( L"ABCDE", 5 );
|
||||
test ( L"a", 1 );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( u"ABCDE", 5 );
|
||||
test ( u"a", 1 );
|
||||
|
||||
test ( U"ABCDE", 5 );
|
||||
test ( U"a", 1 );
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
||||
static_assert ( sv.length() == 2, "" );
|
||||
static_assert ( sv[0] == 'A', "" );
|
||||
static_assert ( sv[1] == 'B', "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// [string.view.capacity], capacity
|
||||
// constexpr size_type size() const noexcept;
|
||||
// constexpr size_type length() const noexcept;
|
||||
// constexpr size_type max_size() const noexcept;
|
||||
// constexpr bool empty() const noexcept;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template<typename SV>
|
||||
void test1 () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr SV sv1;
|
||||
static_assert ( sv1.size() == 0, "" );
|
||||
static_assert ( sv1.empty(), "");
|
||||
static_assert ( sv1.size() == sv1.length(), "" );
|
||||
static_assert ( sv1.max_size() > sv1.size(), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
SV sv1;
|
||||
assert ( sv1.size() == 0 );
|
||||
assert ( sv1.empty());
|
||||
assert ( sv1.size() == sv1.length());
|
||||
assert ( sv1.max_size() > sv1.size());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename CharT>
|
||||
void test2 ( const CharT *s, size_t len ) {
|
||||
{
|
||||
std::experimental::basic_string_view<CharT> sv1 ( s );
|
||||
assert ( sv1.size() == len );
|
||||
assert ( sv1.data() == s );
|
||||
assert ( sv1.empty() == (len == 0));
|
||||
assert ( sv1.size() == sv1.length());
|
||||
assert ( sv1.max_size() > sv1.size());
|
||||
}
|
||||
}
|
||||
|
||||
int main () {
|
||||
typedef std::experimental::string_view string_view;
|
||||
typedef std::experimental::u16string_view u16string_view;
|
||||
typedef std::experimental::u32string_view u32string_view;
|
||||
typedef std::experimental::wstring_view wstring_view;
|
||||
|
||||
test1<string_view> ();
|
||||
test1<u16string_view> ();
|
||||
test1<u32string_view> ();
|
||||
test1<wstring_view> ();
|
||||
|
||||
test2 ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
|
||||
test2 ( "ABCDE", 5 );
|
||||
test2 ( "a", 1 );
|
||||
test2 ( "", 0 );
|
||||
|
||||
test2 ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
|
||||
test2 ( L"ABCDE", 5 );
|
||||
test2 ( L"a", 1 );
|
||||
test2 ( L"", 0 );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test2 ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
|
||||
test2 ( u"ABCDE", 5 );
|
||||
test2 ( u"a", 1 );
|
||||
test2 ( u"", 0 );
|
||||
|
||||
test2 ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
|
||||
test2 ( U"ABCDE", 5 );
|
||||
test2 ( U"a", 1 );
|
||||
test2 ( U"", 0 );
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator==(basic_string_view<charT,traits> lhs, const charT* rhs);
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator==(const charT* lhs, basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S lhs, const typename S::value_type* rhs, bool x)
|
||||
{
|
||||
assert((lhs == rhs) == x);
|
||||
assert((rhs == lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", true);
|
||||
test(S(""), "abcde", false);
|
||||
test(S(""), "abcdefghij", false);
|
||||
test(S(""), "abcdefghijklmnopqrst", false);
|
||||
test(S("abcde"), "", false);
|
||||
test(S("abcde"), "abcde", true);
|
||||
test(S("abcde"), "abcdefghij", false);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", false);
|
||||
test(S("abcdefghij"), "", false);
|
||||
test(S("abcdefghij"), "abcde", false);
|
||||
test(S("abcdefghij"), "abcdefghij", true);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", false);
|
||||
test(S("abcdefghijklmnopqrst"), "", false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
static_assert ( sv1 == "", "" );
|
||||
static_assert ( "" == sv1, "" );
|
||||
static_assert (!(sv1 == "abcde"), "" );
|
||||
static_assert (!("abcde" == sv1), "" );
|
||||
|
||||
static_assert ( sv2 == "abcde", "" );
|
||||
static_assert ( "abcde" == sv2, "" );
|
||||
static_assert (!(sv2 == "abcde0"), "" );
|
||||
static_assert (!("abcde0" == sv2), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator==(const charT* lhs, const basic_string<charT,traits> rhs);
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator==(const basic_string_view<charT,traits> lhs, const CharT* rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const std::string &lhs, S rhs, bool x)
|
||||
{
|
||||
assert((lhs == rhs) == x);
|
||||
assert((rhs == lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), true);
|
||||
test("", S("abcde"), false);
|
||||
test("", S("abcdefghij"), false);
|
||||
test("", S("abcdefghijklmnopqrst"), false);
|
||||
test("abcde", S(""), false);
|
||||
test("abcde", S("abcde"), true);
|
||||
test("abcde", S("abcdefghij"), false);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), false);
|
||||
test("abcdefghij", S(""), false);
|
||||
test("abcdefghij", S("abcde"), false);
|
||||
test("abcdefghij", S("abcdefghij"), true);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), false);
|
||||
test("abcdefghijklmnopqrst", S(""), false);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true);
|
||||
}
|
||||
}
|
||||
#else
|
||||
int main () {}
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator==(const basic_string_view<charT,traits> lhs,
|
||||
// const basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S lhs, S rhs, bool x)
|
||||
{
|
||||
assert((lhs == rhs) == x);
|
||||
assert((rhs == lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), true);
|
||||
test(S(""), S("abcde"), false);
|
||||
test(S(""), S("abcdefghij"), false);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), false);
|
||||
test(S("abcde"), S(""), false);
|
||||
test(S("abcde"), S("abcde"), true);
|
||||
test(S("abcde"), S("abcdefghij"), false);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), false);
|
||||
test(S("abcdefghij"), S(""), false);
|
||||
test(S("abcdefghij"), S("abcde"), false);
|
||||
test(S("abcdefghij"), S("abcdefghij"), true);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2;
|
||||
constexpr SV sv3 { "abcde", 5 };
|
||||
static_assert ( sv1 == sv2, "" );
|
||||
static_assert (!(sv1 == sv3), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator>=(const charT* lhs, basic_string_wiew<charT,traits> rhs);
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator>=(basic_string_wiew<charT,traits> lhs, const charT* rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs >= rhs) == x);
|
||||
assert((rhs >= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), true, true);
|
||||
test("", S("abcde"), false, true);
|
||||
test("", S("abcdefghij"), false, true);
|
||||
test("", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcde", S(""), true, false);
|
||||
test("abcde", S("abcde"), true, true);
|
||||
test("abcde", S("abcdefghij"), false, true);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcdefghij", S(""), true, false);
|
||||
test("abcdefghij", S("abcde"), true, false);
|
||||
test("abcdefghij", S("abcdefghij"), true, true);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcdefghijklmnopqrst", S(""), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true, true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert ( sv1 >= "", "" );
|
||||
static_assert ( "" >= sv1, "" );
|
||||
static_assert (!(sv1 >= "abcde"), "" );
|
||||
static_assert ( "abcde" >= sv1, "" );
|
||||
|
||||
static_assert ( sv2 >= "", "" );
|
||||
static_assert (!("" >= sv2), "" );
|
||||
static_assert ( sv2 >= "abcde", "" );
|
||||
static_assert ( "abcde" >= sv2, "" );
|
||||
static_assert (!(sv2 >= "abcde0"), "" );
|
||||
static_assert ( "abcde0" >= sv2, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
// bool operator>=(basic_string_view<charT,traits> lhs,
|
||||
// const basic_string<charT,traits,Allocator>& rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const typename S::value_type* rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs >= rhs) == x);
|
||||
assert((rhs >= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", true, true);
|
||||
test(S(""), "abcde", false, true);
|
||||
test(S(""), "abcdefghij", false, true);
|
||||
test(S(""), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcde"), "", true, false);
|
||||
test(S("abcde"), "abcde", true, true);
|
||||
test(S("abcde"), "abcdefghij", false, true);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcdefghij"), "", true, false);
|
||||
test(S("abcdefghij"), "abcde", true, false);
|
||||
test(S("abcdefghij"), "abcdefghij", true, true);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator>=(basic_string_view<charT,traits> lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs >= rhs) == x);
|
||||
assert((rhs >= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), true, true);
|
||||
test(S(""), S("abcde"), false, true);
|
||||
test(S(""), S("abcdefghij"), false, true);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcde"), S(""), true, false);
|
||||
test(S("abcde"), S("abcde"), true, true);
|
||||
test(S("abcde"), S("abcdefghij"), false, true);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcdefghij"), S(""), true, false);
|
||||
test(S("abcdefghij"), S("abcde"), true, false);
|
||||
test(S("abcdefghij"), S("abcdefghij"), true, true);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true, true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert ( sv1 >= sv1, "" );
|
||||
static_assert ( sv2 >= sv2, "" );
|
||||
|
||||
static_assert (!(sv1 >= sv2), "" );
|
||||
static_assert ( sv2 >= sv1, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// constexpr template<class charT, class traits, class Allocator>
|
||||
// bool operator>(const charT* lhs, basic_string_wiew<charT,traits> rhs);
|
||||
// constexpr template<class charT, class traits, class Allocator>
|
||||
// bool operator>(basic_string_wiew<charT,traits> lhs, const charT* rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs > rhs) == x);
|
||||
assert((rhs > lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), false, false);
|
||||
test("", S("abcde"), false, true);
|
||||
test("", S("abcdefghij"), false, true);
|
||||
test("", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcde", S(""), true, false);
|
||||
test("abcde", S("abcde"), false, false);
|
||||
test("abcde", S("abcdefghij"), false, true);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcdefghij", S(""), true, false);
|
||||
test("abcdefghij", S("abcde"), true, false);
|
||||
test("abcdefghij", S("abcdefghij"), false, false);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), false, true);
|
||||
test("abcdefghijklmnopqrst", S(""), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), true, false);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false, false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (!(sv1 > ""), "" );
|
||||
static_assert (!("" > sv1), "" );
|
||||
static_assert (!(sv1 > "abcde"), "" );
|
||||
static_assert ( "abcde" > sv1, "" );
|
||||
|
||||
static_assert ( sv2 > "", "" );
|
||||
static_assert (!("" > sv2), "" );
|
||||
static_assert (!(sv2 > "abcde"), "" );
|
||||
static_assert (!("abcde" > sv2), "" );
|
||||
static_assert (!(sv2 > "abcde0"), "" );
|
||||
static_assert ( "abcde0" > sv2, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator>(const basic_string<charT,traits,Allocator>& lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
// bool operator>(basic_string_view<charT,traits> lhs,
|
||||
// const basic_string<charT,traits,Allocator>& rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const typename S::value_type* rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs > rhs) == x);
|
||||
assert((rhs > lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", false, false);
|
||||
test(S(""), "abcde", false, true);
|
||||
test(S(""), "abcdefghij", false, true);
|
||||
test(S(""), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcde"), "", true, false);
|
||||
test(S("abcde"), "abcde", false, false);
|
||||
test(S("abcde"), "abcdefghij", false, true);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcdefghij"), "", true, false);
|
||||
test(S("abcdefghij"), "abcde", true, false);
|
||||
test(S("abcdefghij"), "abcdefghij", false, false);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator>(basic_string_view<charT,traits> lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs > rhs) == x);
|
||||
assert((rhs > lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), false, false);
|
||||
test(S(""), S("abcde"), false, true);
|
||||
test(S(""), S("abcdefghij"), false, true);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcde"), S(""), true, false);
|
||||
test(S("abcde"), S("abcde"), false, false);
|
||||
test(S("abcde"), S("abcdefghij"), false, true);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcdefghij"), S(""), true, false);
|
||||
test(S("abcdefghij"), S("abcde"), true, false);
|
||||
test(S("abcdefghij"), S("abcdefghij"), false, false);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false, false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (!(sv1 > sv1), "" );
|
||||
static_assert (!(sv2 > sv2), "" );
|
||||
|
||||
static_assert (!(sv1 > sv2), "" );
|
||||
static_assert ( sv2 > sv1, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator<=(const charT* lhs, basic_string_wiew<charT,traits> rhs);
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator<=(basic_string_wiew<charT,traits> lhs, const charT* rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs <= rhs) == x);
|
||||
assert((rhs <= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), true, true);
|
||||
test("", S("abcde"), true, false);
|
||||
test("", S("abcdefghij"), true, false);
|
||||
test("", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcde", S(""), false, true);
|
||||
test("abcde", S("abcde"), true, true);
|
||||
test("abcde", S("abcdefghij"), true, false);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcdefghij", S(""), false, true);
|
||||
test("abcdefghij", S("abcde"), false, true);
|
||||
test("abcdefghij", S("abcdefghij"), true, true);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcdefghijklmnopqrst", S(""), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true, true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert ( sv1 <= "", "" );
|
||||
static_assert ( "" <= sv1, "" );
|
||||
static_assert ( sv1 <= "abcde", "" );
|
||||
static_assert (!("abcde" <= sv1), "" );
|
||||
|
||||
static_assert (!(sv2 <= ""), "" );
|
||||
static_assert ( "" <= sv2, "" );
|
||||
static_assert ( sv2 <= "abcde", "" );
|
||||
static_assert ( "abcde" <= sv2, "" );
|
||||
static_assert ( sv2 <= "abcde0", "" );
|
||||
static_assert (!("abcde0" <= sv2), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
// bool operator<=(basic_string_view<charT,traits> lhs,
|
||||
// const basic_string<charT,traits,Allocator>& rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const typename S::value_type* rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs <= rhs) == x);
|
||||
assert((rhs <= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", true, true);
|
||||
test(S(""), "abcde", true, false);
|
||||
test(S(""), "abcdefghij", true, false);
|
||||
test(S(""), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcde"), "", false, true);
|
||||
test(S("abcde"), "abcde", true, true);
|
||||
test(S("abcde"), "abcdefghij", true, false);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcdefghij"), "", false, true);
|
||||
test(S("abcdefghij"), "abcde", false, true);
|
||||
test(S("abcdefghij"), "abcdefghij", true, true);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator<=(basic_string_view<charT,traits> lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs <= rhs) == x);
|
||||
assert((rhs <= lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), true, true);
|
||||
test(S(""), S("abcde"), true, false);
|
||||
test(S(""), S("abcdefghij"), true, false);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcde"), S(""), false, true);
|
||||
test(S("abcde"), S("abcde"), true, true);
|
||||
test(S("abcde"), S("abcdefghij"), true, false);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcdefghij"), S(""), false, true);
|
||||
test(S("abcdefghij"), S("abcde"), false, true);
|
||||
test(S("abcdefghij"), S("abcdefghij"), true, true);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true, true);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert ( sv1 <= sv1, "" );
|
||||
static_assert ( sv2 <= sv2, "" );
|
||||
|
||||
static_assert ( sv1 <= sv2, "" );
|
||||
static_assert (!(sv2 <= sv1), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator<(const charT* lhs, basic_string_wiew<charT,traits> rhs);
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator<(basic_string_wiew<charT,traits> lhs, const charT* rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs < rhs) == x);
|
||||
assert((rhs < lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), false, false);
|
||||
test("", S("abcde"), true, false);
|
||||
test("", S("abcdefghij"), true, false);
|
||||
test("", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcde", S(""), false, true);
|
||||
test("abcde", S("abcde"), false, false);
|
||||
test("abcde", S("abcdefghij"), true, false);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcdefghij", S(""), false, true);
|
||||
test("abcdefghij", S("abcde"), false, true);
|
||||
test("abcdefghij", S("abcdefghij"), false, false);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), true, false);
|
||||
test("abcdefghijklmnopqrst", S(""), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), false, true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false, false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (!(sv1 < ""), "" );
|
||||
static_assert (!("" < sv1), "" );
|
||||
static_assert ( sv1 < "abcde", "" );
|
||||
static_assert (!("abcde" < sv1), "" );
|
||||
|
||||
static_assert (!(sv2 < ""), "" );
|
||||
static_assert ( "" < sv2, "" );
|
||||
static_assert (!(sv2 < "abcde"), "" );
|
||||
static_assert (!("abcde" < sv2), "" );
|
||||
static_assert ( sv2 < "abcde0", "" );
|
||||
static_assert (!("abcde0" < sv2), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator<(const basic_string<charT,traits,Allocator>& lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
// bool operator<(basic_string_view<charT,traits> lhs,
|
||||
// const basic_string<charT,traits,Allocator>& rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const typename S::value_type* rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs < rhs) == x);
|
||||
assert((rhs < lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", false, false);
|
||||
test(S(""), "abcde", true, false);
|
||||
test(S(""), "abcdefghij", true, false);
|
||||
test(S(""), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcde"), "", false, true);
|
||||
test(S("abcde"), "abcde", false, false);
|
||||
test(S("abcde"), "abcdefghij", true, false);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcdefghij"), "", false, true);
|
||||
test(S("abcdefghij"), "abcde", false, true);
|
||||
test(S("abcdefghij"), "abcdefghij", false, false);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", true, false);
|
||||
test(S("abcdefghijklmnopqrst"), "", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", false, true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator<(basic_string_view<charT,traits> lhs,
|
||||
// basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& lhs, const S& rhs, bool x, bool y)
|
||||
{
|
||||
assert((lhs < rhs) == x);
|
||||
assert((rhs < lhs) == y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), false, false);
|
||||
test(S(""), S("abcde"), true, false);
|
||||
test(S(""), S("abcdefghij"), true, false);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcde"), S(""), false, true);
|
||||
test(S("abcde"), S("abcde"), false, false);
|
||||
test(S("abcde"), S("abcdefghij"), true, false);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcdefghij"), S(""), false, true);
|
||||
test(S("abcdefghij"), S("abcde"), false, true);
|
||||
test(S("abcdefghij"), S("abcdefghij"), false, false);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true, false);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false, true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false, false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (!(sv1 < sv1), "" );
|
||||
static_assert (!(sv2 < sv2), "" );
|
||||
|
||||
static_assert ( sv1 < sv2, "" );
|
||||
static_assert (!(sv2 < sv1), "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator!=(basic_string_view<charT,traits> lhs, const charT* rhs);
|
||||
// template<class charT, class traits>
|
||||
// constexpr bool operator!=(const charT* lhs, basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S lhs, const typename S::value_type* rhs, bool x)
|
||||
{
|
||||
assert((lhs != rhs) == x);
|
||||
assert((rhs != lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), "", false);
|
||||
test(S(""), "abcde", true);
|
||||
test(S(""), "abcdefghij", true);
|
||||
test(S(""), "abcdefghijklmnopqrst", true);
|
||||
test(S("abcde"), "", true);
|
||||
test(S("abcde"), "abcde", false);
|
||||
test(S("abcde"), "abcdefghij", true);
|
||||
test(S("abcde"), "abcdefghijklmnopqrst", true);
|
||||
test(S("abcdefghij"), "", true);
|
||||
test(S("abcdefghij"), "abcde", true);
|
||||
test(S("abcdefghij"), "abcdefghij", false);
|
||||
test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
|
||||
test(S("abcdefghijklmnopqrst"), "", true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcde", true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
|
||||
test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (!(sv1 != ""), "" );
|
||||
static_assert (!("" != sv1), "" );
|
||||
static_assert ( sv1 != "abcde", "" );
|
||||
static_assert ( "abcde" != sv1, "" );
|
||||
|
||||
static_assert (!(sv2 != "abcde"), "" );
|
||||
static_assert (!("abcde" != sv2), "" );
|
||||
static_assert ( sv2 != "abcde0", "" );
|
||||
static_assert ( "abcde0" != sv2, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator!=(const basic_string<charT, traits, Allocator> &lhs, basic_string_view<charT,traits> rhs);
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// bool operator!=(basic_string_view<charT,traits> lhs, const basic_string<charT, traits, Allocator> &rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const std::string &lhs, S rhs, bool x)
|
||||
{
|
||||
assert((lhs != rhs) == x);
|
||||
assert((rhs != lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test("", S(""), false);
|
||||
test("", S("abcde"), true);
|
||||
test("", S("abcdefghij"), true);
|
||||
test("", S("abcdefghijklmnopqrst"), true);
|
||||
test("abcde", S(""), true);
|
||||
test("abcde", S("abcde"), false);
|
||||
test("abcde", S("abcdefghij"), true);
|
||||
test("abcde", S("abcdefghijklmnopqrst"), true);
|
||||
test("abcdefghij", S(""), true);
|
||||
test("abcdefghij", S("abcde"), true);
|
||||
test("abcdefghij", S("abcdefghij"), false);
|
||||
test("abcdefghij", S("abcdefghijklmnopqrst"), true);
|
||||
test("abcdefghijklmnopqrst", S(""), true);
|
||||
test("abcdefghijklmnopqrst", S("abcde"), true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghij"), true);
|
||||
test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class charT, class traits, class Allocator>
|
||||
// constexpr bool operator!=(const basic_string_view<charT,traits> lhs,
|
||||
// const basic_string_view<charT,traits> rhs);
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S lhs, S rhs, bool x)
|
||||
{
|
||||
assert((lhs != rhs) == x);
|
||||
assert((rhs != lhs) == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), S(""), false);
|
||||
test(S(""), S("abcde"), true);
|
||||
test(S(""), S("abcdefghij"), true);
|
||||
test(S(""), S("abcdefghijklmnopqrst"), true);
|
||||
test(S("abcde"), S(""), true);
|
||||
test(S("abcde"), S("abcde"), false);
|
||||
test(S("abcde"), S("abcdefghij"), true);
|
||||
test(S("abcde"), S("abcdefghijklmnopqrst"), true);
|
||||
test(S("abcdefghij"), S(""), true);
|
||||
test(S("abcdefghij"), S("abcde"), true);
|
||||
test(S("abcdefghij"), S("abcdefghij"), false);
|
||||
test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
|
||||
test(S("abcdefghijklmnopqrst"), S(""), true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcde"), true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
|
||||
test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2;
|
||||
constexpr SV sv3 { "abcde", 5 };
|
||||
static_assert (!( sv1 != sv2), "" );
|
||||
static_assert ( sv1 != sv3, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view () noexcept;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
template<typename T>
|
||||
void test () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr T sv1;
|
||||
static_assert ( sv1.size() == 0, "" );
|
||||
static_assert ( sv1.empty(), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
T sv1;
|
||||
assert ( sv1.size() == 0 );
|
||||
assert ( sv1.empty());
|
||||
}
|
||||
}
|
||||
|
||||
int main () {
|
||||
typedef std::experimental::string_view string_view;
|
||||
typedef std::experimental::u16string_view u16string_view;
|
||||
typedef std::experimental::u32string_view u32string_view;
|
||||
typedef std::experimental::wstring_view wstring_view;
|
||||
|
||||
test<string_view> ();
|
||||
test<u16string_view> ();
|
||||
test<u32string_view> ();
|
||||
test<wstring_view> ();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view(const _CharT* _s)
|
||||
// : __data (_s), __size(_Traits::length(_s)) {}
|
||||
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template<typename CharT>
|
||||
size_t StrLen ( const CharT *s ) {
|
||||
size_t retVal = 0;
|
||||
while ( *s != 0 ) { ++retVal; ++s; }
|
||||
return retVal;
|
||||
}
|
||||
|
||||
template<typename CharT>
|
||||
void test ( const CharT *s ) {
|
||||
std::experimental::basic_string_view<CharT> sv1 ( s );
|
||||
assert ( sv1.size() == StrLen( s ));
|
||||
assert ( sv1.data() == s );
|
||||
}
|
||||
|
||||
|
||||
int main () {
|
||||
|
||||
test ( "QBCDE" );
|
||||
test ( "A" );
|
||||
test ( "" );
|
||||
|
||||
test ( L"QBCDE" );
|
||||
test ( L"A" );
|
||||
test ( L"" );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( u"QBCDE" );
|
||||
test ( u"A" );
|
||||
test ( u"" );
|
||||
|
||||
test ( U"QBCDE" );
|
||||
test ( U"A" );
|
||||
test ( U"" );
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::experimental::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" );
|
||||
static_assert ( sv1.size() == 5, "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view(const _CharT* _s, size_type _len)
|
||||
// : __data (_s), __size(_len) {}
|
||||
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template<typename CharT>
|
||||
void test ( const CharT *s, size_t sz ) {
|
||||
{
|
||||
std::experimental::basic_string_view<CharT> sv1 ( s, sz );
|
||||
assert ( sv1.size() == sz );
|
||||
assert ( sv1.data() == s );
|
||||
}
|
||||
}
|
||||
|
||||
int main () {
|
||||
|
||||
test ( "QBCDE", 5 );
|
||||
test ( "QBCDE", 2 );
|
||||
test ( "", 0 );
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr const char *s = "QBCDE";
|
||||
constexpr std::experimental::basic_string_view<char> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
test ( L"QBCDE", 5 );
|
||||
test ( L"QBCDE", 2 );
|
||||
test ( L"", 0 );
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr const wchar_t *s = L"QBCDE";
|
||||
constexpr std::experimental::basic_string_view<wchar_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( u"QBCDE", 5 );
|
||||
test ( u"QBCDE", 2 );
|
||||
test ( u"", 0 );
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr const char16_t *s = u"QBCDE";
|
||||
constexpr std::experimental::basic_string_view<char16_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
test ( U"QBCDE", 5 );
|
||||
test ( U"QBCDE", 2 );
|
||||
test ( U"", 0 );
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr const char32_t *s = U"QBCDE";
|
||||
constexpr std::experimental::basic_string_view<char32_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
template<typename CharT, typename Traits>
|
||||
void test ( const std::basic_string<CharT, Traits> &str ) {
|
||||
std::experimental::basic_string_view<CharT, Traits> sv1 ( str );
|
||||
assert ( sv1.size() == str.size());
|
||||
assert ( sv1.data() == str.data());
|
||||
}
|
||||
|
||||
int main () {
|
||||
|
||||
test ( std::string("QBCDE") );
|
||||
test ( std::string("") );
|
||||
test ( std::string() );
|
||||
|
||||
test ( std::wstring(L"QBCDE") );
|
||||
test ( std::wstring(L"") );
|
||||
test ( std::wstring() );
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
test ( std::u16string{u"QBCDE"} );
|
||||
test ( std::u16string{u""} );
|
||||
test ( std::u16string{} );
|
||||
|
||||
test ( std::u32string{U"QBCDE"} );
|
||||
test ( std::u32string{U""} );
|
||||
test ( std::u32string{} );
|
||||
#endif
|
||||
|
||||
test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
|
||||
test ( std::basic_string<char, dummy_char_traits>("") );
|
||||
test ( std::basic_string<char, dummy_char_traits>() );
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
int main () {
|
||||
using string_view = std::experimental::basic_string_view<char>;
|
||||
using string = std:: basic_string <char, dummy_char_traits>;
|
||||
|
||||
{
|
||||
string s{"QBCDE"};
|
||||
string_view sv1 ( s );
|
||||
assert ( sv1.size() == s.size());
|
||||
assert ( sv1.data() == s.data());
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
int main () {
|
||||
using string_view = std::experimental::basic_string_view<char, dummy_char_traits>;
|
||||
using string = std:: basic_string <char>;
|
||||
|
||||
{
|
||||
string s{"QBCDE"};
|
||||
string_view sv1 ( s );
|
||||
assert ( sv1.size() == s.size());
|
||||
assert ( sv1.data() == s.data());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr size_type find(charT c, size_type pos = 0) const;
|
||||
|
||||
#include <experimental/string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "constexpr_char_traits.hpp"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s, typename S::value_type c, typename S::size_type pos,
|
||||
typename S::size_type x)
|
||||
{
|
||||
assert(s.find(c, pos) == x);
|
||||
if (x != S::npos)
|
||||
assert(pos <= x && x + 1 <= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s, typename S::value_type c, typename S::size_type x)
|
||||
{
|
||||
assert(s.find(c) == x);
|
||||
if (x != S::npos)
|
||||
assert(0 <= x && x + 1 <= s.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::experimental::string_view S;
|
||||
test(S(""), 'c', 0, S::npos);
|
||||
test(S(""), 'c', 1, S::npos);
|
||||
test(S("abcde"), 'c', 0, 2);
|
||||
test(S("abcde"), 'c', 1, 2);
|
||||
test(S("abcde"), 'c', 2, 2);
|
||||
test(S("abcde"), 'c', 4, S::npos);
|
||||
test(S("abcde"), 'c', 5, S::npos);
|
||||
test(S("abcde"), 'c', 6, S::npos);
|
||||
test(S("abcdeabcde"), 'c', 0, 2);
|
||||
test(S("abcdeabcde"), 'c', 1, 2);
|
||||
test(S("abcdeabcde"), 'c', 5, 7);
|
||||
test(S("abcdeabcde"), 'c', 9, S::npos);
|
||||
test(S("abcdeabcde"), 'c', 10, S::npos);
|
||||
test(S("abcdeabcde"), 'c', 11, S::npos);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 0, 2);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 1, 2);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 10, 12);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 19, S::npos);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 20, S::npos);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 21, S::npos);
|
||||
|
||||
test(S(""), 'c', S::npos);
|
||||
test(S("abcde"), 'c', 2);
|
||||
test(S("abcdeabcde"), 'c', 2);
|
||||
test(S("abcdeabcdeabcdeabcde"), 'c', 2);
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
|
||||
constexpr SV sv1;
|
||||
constexpr SV sv2 { "abcde", 5 };
|
||||
|
||||
static_assert (sv1.find( 'c', 0 ) == SV::npos, "" );
|
||||
static_assert (sv1.find( 'c', 1 ) == SV::npos, "" );
|
||||
static_assert (sv2.find( 'c', 0 ) == 2, "" );
|
||||
static_assert (sv2.find( 'c', 1 ) == 2, "" );
|
||||
static_assert (sv2.find( 'c', 2 ) == 2, "" );
|
||||
static_assert (sv2.find( 'c', 3 ) == SV::npos, "" );
|
||||
static_assert (sv2.find( 'c', 4 ) == SV::npos, "" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user