[libcxx-commits] [libcxx] 3581fd3 - [libc++] [test] Remove `using std::any{, _cast}` from std/utilities/any/. NFCI.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 16 08:00:17 PST 2022
Author: Arthur O'Dwyer
Date: 2022-02-16T11:00:02-05:00
New Revision: 3581fd32ee95ce282b816d35008ca2d0d42e2775
URL: https://github.com/llvm/llvm-project/commit/3581fd32ee95ce282b816d35008ca2d0d42e2775
DIFF: https://github.com/llvm/llvm-project/commit/3581fd32ee95ce282b816d35008ca2d0d42e2775.diff
LOG: [libc++] [test] Remove `using std::any{,_cast}` from std/utilities/any/. NFCI.
Differential Revision: https://reviews.llvm.org/D119863
Added:
Modified:
libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp
libcxx/test/libcxx/utilities/any/small_type.pass.cpp
libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp
libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp
libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp
libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp
libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp
libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp
libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp
libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp
libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp
libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp
libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp
libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp b/libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp
index 04e853d0ae766..230ff8c2a06c7 100644
--- a/libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp
+++ b/libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp
@@ -18,9 +18,8 @@
int main(int, char**)
{
- using std::any;
- static_assert(sizeof(any) == sizeof(void*)*4, "");
- static_assert(alignof(any) == alignof(void*), "");
+ static_assert(sizeof(std::any) == sizeof(void*)*4, "");
+ static_assert(alignof(std::any) == alignof(void*), "");
return 0;
}
diff --git a/libcxx/test/libcxx/utilities/any/small_type.pass.cpp b/libcxx/test/libcxx/utilities/any/small_type.pass.cpp
index fa7b7819678cf..65c7d34ff6ea8 100644
--- a/libcxx/test/libcxx/utilities/any/small_type.pass.cpp
+++ b/libcxx/test/libcxx/utilities/any/small_type.pass.cpp
@@ -57,7 +57,6 @@ struct alignas(DoubleBufferAlignment) OverSizeAndAlignedType {
int main(int, char**)
{
- using std::any;
using std::__any_imp::_IsSmallObject;
static_assert(_IsSmallObject<small>::value, "");
static_assert(_IsSmallObject<void*>::value, "");
diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp
index b59bb76e5b760..f235b70aaddf4 100644
--- a/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp
@@ -13,7 +13,7 @@
// <any>
-// any& operator=(any const &);
+// any& operator=(const any&);
// Test copy assignment
@@ -24,9 +24,6 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
template <class LHS, class RHS>
void test_copy_assign() {
assert(LHS::count == 0);
@@ -34,8 +31,8 @@ void test_copy_assign() {
LHS::reset();
RHS::reset();
{
- any lhs(LHS(1));
- any const rhs(RHS(2));
+ std::any lhs = LHS(1);
+ const std::any rhs = RHS(2);
assert(LHS::count == 1);
assert(RHS::count == 1);
@@ -59,8 +56,8 @@ void test_copy_assign_empty() {
assert(LHS::count == 0);
LHS::reset();
{
- any lhs;
- any const rhs(LHS(42));
+ std::any lhs;
+ const std::any rhs = LHS(42);
assert(LHS::count == 1);
assert(LHS::copied == 0);
@@ -76,8 +73,8 @@ void test_copy_assign_empty() {
assert(LHS::count == 0);
LHS::reset();
{
- any lhs(LHS(1));
- any const rhs;
+ std::any lhs = LHS(1);
+ const std::any rhs;
assert(LHS::count == 1);
assert(LHS::copied == 0);
@@ -96,18 +93,18 @@ void test_copy_assign_empty() {
void test_copy_assign_self() {
// empty
{
- any a;
- a = (any &)a;
+ std::any a;
+ a = (std::any&)a;
assertEmpty(a);
assert(globalMemCounter.checkOutstandingNewEq(0));
}
assert(globalMemCounter.checkOutstandingNewEq(0));
// small
{
- any a((small(1)));
+ std::any a = small(1);
assert(small::count == 1);
- a = (any &)a;
+ a = (std::any&)a;
assert(small::count == 1);
assertContains<small>(a, 1);
@@ -117,10 +114,10 @@ void test_copy_assign_self() {
assert(globalMemCounter.checkOutstandingNewEq(0));
// large
{
- any a(large(1));
+ std::any a = large(1);
assert(large::count == 1);
- a = (any &)a;
+ a = (std::any&)a;
assert(large::count == 1);
assertContains<large>(a, 1);
@@ -135,11 +132,11 @@ void test_copy_assign_throws()
{
#if !defined(TEST_HAS_NO_EXCEPTIONS)
auto try_throw =
- [](any& lhs, any const& rhs) {
+ [](std::any& lhs, const std::any& rhs) {
try {
lhs = rhs;
assert(false);
- } catch (my_any_exception const &) {
+ } catch (const my_any_exception&) {
// do nothing
} catch (...) {
assert(false);
@@ -147,8 +144,8 @@ void test_copy_assign_throws()
};
// const lvalue to empty
{
- any lhs;
- any const rhs((Tp(1)));
+ std::any lhs;
+ const std::any rhs = Tp(1);
assert(Tp::count == 1);
try_throw(lhs, rhs);
@@ -158,8 +155,8 @@ void test_copy_assign_throws()
assertContains<Tp>(rhs, 1);
}
{
- any lhs((small(2)));
- any const rhs((Tp(1)));
+ std::any lhs = small(2);
+ const std::any rhs = Tp(1);
assert(small::count == 1);
assert(Tp::count == 1);
@@ -171,8 +168,8 @@ void test_copy_assign_throws()
assertContains<Tp>(rhs, 1);
}
{
- any lhs((large(2)));
- any const rhs((Tp(1)));
+ std::any lhs = large(2);
+ const std::any rhs = Tp(1);
assert(large::count == 1);
assert(Tp::count == 1);
diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp
index 4a1b0fc8eed1d..ec0b6c00a72e1 100644
--- a/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp
@@ -23,18 +23,15 @@
#include "any_helpers.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
template <class LHS, class RHS>
void test_move_assign() {
assert(LHS::count == 0);
assert(RHS::count == 0);
{
LHS const s1(1);
- any a(s1);
+ std::any a = s1;
RHS const s2(2);
- any a2(s2);
+ std::any a2 = s2;
assert(LHS::count == 2);
assert(RHS::count == 2);
@@ -58,8 +55,8 @@ template <class LHS>
void test_move_assign_empty() {
assert(LHS::count == 0);
{
- any a;
- any a2((LHS(1)));
+ std::any a;
+ std::any a2 = LHS(1);
assert(LHS::count == 1);
@@ -75,8 +72,8 @@ void test_move_assign_empty() {
}
assert(LHS::count == 0);
{
- any a((LHS(1)));
- any a2;
+ std::any a = LHS(1);
+ std::any a2;
assert(LHS::count == 1);
@@ -91,12 +88,9 @@ void test_move_assign_empty() {
}
void test_move_assign_noexcept() {
- any a1;
- any a2;
- static_assert(
- noexcept(a1 = std::move(a2))
- , "any & operator=(any &&) must be noexcept"
- );
+ std::any a1;
+ std::any a2;
+ ASSERT_NOEXCEPT(a1 = std::move(a2));
}
int main(int, char**) {
diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp
index f054cd8a719aa..a4a4095daa274 100644
--- a/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp
@@ -25,9 +25,6 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
template <class LHS, class RHS>
void test_assign_value() {
assert(LHS::count == 0);
@@ -35,8 +32,8 @@ void test_assign_value() {
LHS::reset();
RHS::reset();
{
- any lhs(LHS(1));
- any const rhs(RHS(2));
+ std::any lhs = LHS(1);
+ const std::any rhs = RHS(2);
assert(LHS::count == 1);
assert(RHS::count == 1);
@@ -56,8 +53,8 @@ void test_assign_value() {
LHS::reset();
RHS::reset();
{
- any lhs(LHS(1));
- any rhs(RHS(2));
+ std::any lhs = LHS(1);
+ std::any rhs = RHS(2);
assert(LHS::count == 1);
assert(RHS::count == 1);
@@ -84,7 +81,7 @@ void test_assign_value_empty() {
assert(RHS::count == 0);
RHS::reset();
{
- any lhs;
+ std::any lhs;
RHS rhs(42);
assert(RHS::count == 1);
assert(RHS::copied == 0);
@@ -99,7 +96,7 @@ void test_assign_value_empty() {
assert(RHS::count == 0);
RHS::reset();
{
- any lhs;
+ std::any lhs;
RHS rhs(42);
assert(RHS::count == 1);
assert(RHS::moved == 0);
@@ -120,12 +117,12 @@ template <class Tp, bool Move = false>
void test_assign_throws() {
#if !defined(TEST_HAS_NO_EXCEPTIONS)
auto try_throw =
- [](any& lhs, Tp& rhs) {
+ [](std::any& lhs, Tp& rhs) {
try {
Move ? lhs = std::move(rhs)
: lhs = rhs;
assert(false);
- } catch (my_any_exception const &) {
+ } catch (const my_any_exception&) {
// do nothing
} catch (...) {
assert(false);
@@ -133,7 +130,7 @@ void test_assign_throws() {
};
// const lvalue to empty
{
- any lhs;
+ std::any lhs;
Tp rhs(1);
assert(Tp::count == 1);
@@ -143,8 +140,8 @@ void test_assign_throws() {
assertEmpty<Tp>(lhs);
}
{
- any lhs((small(2)));
- Tp rhs(1);
+ std::any lhs = small(2);
+ Tp rhs(1);
assert(small::count == 1);
assert(Tp::count == 1);
@@ -155,7 +152,7 @@ void test_assign_throws() {
assertContains<small>(lhs, 2);
}
{
- any lhs((large(2)));
+ std::any lhs = large(2);
Tp rhs(1);
assert(large::count == 1);
assert(Tp::count == 1);
diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp
index 579ea24cc18ef..892ef43d36407 100644
--- a/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp
@@ -22,18 +22,15 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
template <class Type>
void test_copy_throws() {
#if !defined(TEST_HAS_NO_EXCEPTIONS)
assert(Type::count == 0);
{
- any const a((Type(42)));
+ const std::any a = Type(42);
assert(Type::count == 1);
try {
- any const a2(a);
+ const std::any a2(a);
assert(false);
} catch (my_any_exception const &) {
// do nothing
@@ -49,8 +46,8 @@ void test_copy_throws() {
void test_copy_empty() {
DisableAllocationGuard g; ((void)g); // No allocations should occur.
- any a1;
- any a2(a1);
+ std::any a1;
+ std::any a2(a1);
assertEmpty(a1);
assertEmpty(a2);
@@ -64,11 +61,11 @@ void test_copy()
assert(Type::count == 0);
Type::reset();
{
- any a((Type(42)));
+ std::any a = Type(42);
assert(Type::count == 1);
assert(Type::copied == 0);
- any a2(a);
+ std::any a2(a);
assert(Type::copied == 1);
assert(Type::count == 2);
diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp
index b5efe9e8b75b9..a20d22c1073fa 100644
--- a/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp
@@ -22,10 +22,9 @@
int main(int, char**)
{
- using std::any;
{
static_assert(
- std::is_nothrow_default_constructible<any>::value
+ std::is_nothrow_default_constructible<std::any>::value
, "Must be default constructible"
);
}
@@ -38,7 +37,7 @@ int main(int, char**)
}
{
DisableAllocationGuard g; ((void)g);
- any const a;
+ const std::any a;
assertEmpty(a);
}
diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
index 0c8b668ddaa4f..a1205bfd0777d 100644
--- a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp
@@ -32,9 +32,6 @@
#include "test_macros.h"
#include "test_convertible.h"
-using std::any;
-using std::any_cast;
-
template <class Type>
void test_in_place_type() {
// constructing from a small type should perform no allocations.
@@ -42,7 +39,7 @@ void test_in_place_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Type>);
+ std::any a(std::in_place_type<Type>);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -52,7 +49,7 @@ void test_in_place_type() {
assert(Type::count == 0);
Type::reset();
{ // Test that the in_place argument is properly decayed
- any a(std::in_place_type<Type&>);
+ std::any a(std::in_place_type<Type&>);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -62,7 +59,7 @@ void test_in_place_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Type>, 101);
+ std::any a(std::in_place_type<Type>, 101);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -72,7 +69,7 @@ void test_in_place_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Type>, -1, 42, -1);
+ std::any a(std::in_place_type<Type>, -1, 42, -1);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -88,21 +85,21 @@ void test_in_place_type_tracked() {
// constructing from a small type should perform no allocations.
DisableAllocationGuard g(isSmallType<Type>()); ((void)g);
{
- any a(std::in_place_type<Type>);
+ std::any a(std::in_place_type<Type>);
assertArgsMatch<Type>(a);
}
{
- any a(std::in_place_type<Type>, -1, 42, -1);
+ std::any a(std::in_place_type<Type>, -1, 42, -1);
assertArgsMatch<Type, int, int, int>(a);
}
// initializer_list constructor tests
{
- any a(std::in_place_type<Type>, {-1, 42, -1});
+ std::any a(std::in_place_type<Type>, {-1, 42, -1});
assertArgsMatch<Type, std::initializer_list<int>>(a);
}
{
int x = 42;
- any a(std::in_place_type<Type&>, {-1, 42, -1}, x);
+ std::any a(std::in_place_type<Type&>, {-1, 42, -1}, x);
assertArgsMatch<Type, std::initializer_list<int>, int&>(a);
}
}
@@ -113,24 +110,24 @@ void test_in_place_type_decayed() {
{
using Type = decltype(test_func);
using DecayT = void(*)();
- any a(std::in_place_type<Type>, test_func);
+ std::any a(std::in_place_type<Type>, test_func);
assert(containsType<DecayT>(a));
- assert(any_cast<DecayT>(a) == test_func);
+ assert(std::any_cast<DecayT>(a) == test_func);
}
{
int my_arr[5];
using Type = int(&)[5];
using DecayT = int*;
- any a(std::in_place_type<Type>, my_arr);
+ std::any a(std::in_place_type<Type>, my_arr);
assert(containsType<DecayT>(a));
- assert(any_cast<DecayT>(a) == my_arr);
+ assert(std::any_cast<DecayT>(a) == my_arr);
}
{
using Type = int[5];
using DecayT = int*;
- any a(std::in_place_type<Type>);
+ std::any a(std::in_place_type<Type>);
assert(containsType<DecayT>(a));
- assert(any_cast<DecayT>(a) == nullptr);
+ assert(std::any_cast<DecayT>(a) == nullptr);
}
}
diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp
index d8710213f1715..d70b6888015d3 100644
--- a/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -24,9 +24,6 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
// Moves are always noexcept. The throws_on_move object
// must be stored dynamically so the pointer is moved and
// not the stored object.
@@ -36,12 +33,12 @@ void test_move_does_not_throw()
assert(throws_on_move::count == 0);
{
throws_on_move v(42);
- any a(v);
+ std::any a = v;
assert(throws_on_move::count == 2);
// No allocations should be performed after this point.
DisableAllocationGuard g; ((void)g);
try {
- any const a2(std::move(a));
+ const std::any a2 = std::move(a);
assertEmpty(a);
assertContains<throws_on_move>(a2, 42);
} catch (...) {
@@ -57,8 +54,8 @@ void test_move_does_not_throw()
void test_move_empty() {
DisableAllocationGuard g; ((void)g); // no allocations should be performed.
- any a1;
- any a2(std::move(a1));
+ std::any a1;
+ std::any a2 = std::move(a1);
assertEmpty(a1);
assertEmpty(a2);
@@ -69,7 +66,7 @@ void test_move() {
assert(Type::count == 0);
Type::reset();
{
- any a((Type(42)));
+ std::any a = Type(42);
assert(Type::count == 1);
assert(Type::copied == 0);
assert(Type::moved == 1);
@@ -77,7 +74,7 @@ void test_move() {
// Moving should not perform allocations since it must be noexcept.
DisableAllocationGuard g; ((void)g);
- any a2(std::move(a));
+ std::any a2 = std::move(a);
assert(Type::moved == 1 || Type::moved == 2); // zero or more move operations can be performed.
assert(Type::copied == 0); // no copies can be performed.
@@ -93,12 +90,8 @@ void test_move() {
int main(int, char**)
{
// noexcept test
- {
- static_assert(
- std::is_nothrow_move_constructible<any>::value
- , "any must be nothrow move constructible"
- );
- }
+ static_assert(std::is_nothrow_move_constructible<std::any>::value);
+
test_move<small>();
test_move<large>();
test_move_empty();
diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp
index d55bbda741439..c7ccc588b2ea9 100644
--- a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -29,21 +29,18 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
template <class Type>
void test_copy_value_throws()
{
#if !defined(TEST_HAS_NO_EXCEPTIONS)
assert(Type::count == 0);
{
- Type const t(42);
+ const Type t(42);
assert(Type::count == 1);
try {
- any const a2(t);
+ std::any a2 = t;
assert(false);
- } catch (my_any_exception const &) {
+ } catch (const my_any_exception&) {
// do nothing
} catch (...) {
assert(false);
@@ -63,9 +60,9 @@ void test_move_value_throws()
throws_on_move v;
assert(throws_on_move::count == 1);
try {
- any const a(std::move(v));
+ std::any a = std::move(v);
assert(false);
- } catch (my_any_exception const &) {
+ } catch (const my_any_exception&) {
// do nothing
} catch (...) {
assert(false);
@@ -86,7 +83,7 @@ void test_copy_move_value() {
Type t(42);
assert(Type::count == 1);
- any a(t);
+ std::any a = t;
assert(Type::count == 2);
assert(Type::copied == 1);
@@ -99,7 +96,7 @@ void test_copy_move_value() {
Type t(42);
assert(Type::count == 1);
- any a(std::move(t));
+ std::any a = std::move(t);
assert(Type::count == 2);
assert(Type::copied == 0);
diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
index 5168d69ddea4a..7c5fbfec9bf06 100644
--- a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
@@ -24,9 +24,6 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
struct Tracked {
static int count;
Tracked() {++count;}
@@ -41,7 +38,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>();
@@ -57,7 +54,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>(101);
@@ -73,7 +70,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>(-1, 42, -1);
@@ -95,7 +92,7 @@ void test_emplace_type_tracked() {
// constructing from a small type should perform no allocations.
DisableAllocationGuard g(isSmallType<Type>()); ((void)g);
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>();
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
@@ -105,7 +102,7 @@ void test_emplace_type_tracked() {
assertArgsMatch<Type>(a);
}
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>(-1, 42, -1);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
@@ -116,7 +113,7 @@ void test_emplace_type_tracked() {
}
// initializer_list constructor tests
{
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>({-1, 42, -1});
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
@@ -127,7 +124,7 @@ void test_emplace_type_tracked() {
}
{
int x = 42;
- any a(std::in_place_type<Tracked>);
+ std::any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
auto &v = a.emplace<Type>({-1, 42, -1}, x);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp
index 4b4aa2923662c..7499ed0209454 100644
--- a/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp
@@ -23,17 +23,10 @@
int main(int, char**)
{
- using std::any;
- using std::any_cast;
// empty
{
- any a;
-
- // noexcept check
- static_assert(
- noexcept(a.reset())
- , "any.reset() must be noexcept"
- );
+ std::any a;
+ ASSERT_NOEXCEPT(a.reset());
assertEmpty(a);
@@ -43,7 +36,7 @@ int main(int, char**)
}
// small object
{
- any a((small(1)));
+ std::any a = small(1);
assert(small::count == 1);
assertContains<small>(a, 1);
@@ -54,7 +47,7 @@ int main(int, char**)
}
// large object
{
- any a(large(1));
+ std::any a = large(1);
assert(large::count == 1);
assertContains<large>(a, 1);
diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
index ee5684ee2ea8c..9e075866fc3dd 100644
--- a/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -23,16 +23,13 @@
#include "test_macros.h"
#include "any_helpers.h"
-using std::any;
-using std::any_cast;
-
template <class LHS, class RHS>
void test_swap() {
assert(LHS::count == 0);
assert(RHS::count == 0);
{
- any a1((LHS(1)));
- any a2(RHS{2});
+ std::any a1 = LHS(1);
+ std::any a2 = RHS(2);
assert(LHS::count == 1);
assert(RHS::count == 1);
@@ -54,8 +51,8 @@ template <class Tp>
void test_swap_empty() {
assert(Tp::count == 0);
{
- any a1((Tp(1)));
- any a2;
+ std::any a1 = Tp(1);
+ std::any a2;
assert(Tp::count == 1);
a1.swap(a2);
@@ -67,8 +64,8 @@ void test_swap_empty() {
}
assert(Tp::count == 0);
{
- any a1((Tp(1)));
- any a2;
+ std::any a1 = Tp(1);
+ std::any a2;
assert(Tp::count == 1);
a2.swap(a1);
@@ -84,24 +81,21 @@ void test_swap_empty() {
void test_noexcept()
{
- any a1;
- any a2;
- static_assert(
- noexcept(a1.swap(a2))
- , "any::swap(any&) must be noexcept"
- );
+ std::any a1;
+ std::any a2;
+ ASSERT_NOEXCEPT(a1.swap(a2));
}
void test_self_swap() {
{
// empty
- any a;
+ std::any a;
a.swap(a);
assertEmpty(a);
}
{ // small
using T = small;
- any a{T{42}};
+ std::any a = T(42);
T::reset();
a.swap(a);
assertContains<T>(a, 42);
@@ -112,7 +106,7 @@ void test_self_swap() {
assert(small::count == 0);
{ // large
using T = large;
- any a{T{42}};
+ std::any a = T(42);
T::reset();
a.swap(a);
assertContains<T>(a, 42);
diff --git a/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp
index 6469269e97f70..2e6c007ca5578 100644
--- a/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp
@@ -20,15 +20,13 @@
int main(int, char**)
{
- using std::any;
- // noexcept test
{
- any a;
- static_assert(noexcept(a.has_value()), "any::has_value() must be noexcept");
+ std::any a;
+ ASSERT_NOEXCEPT(a.has_value());
}
// empty
{
- any a;
+ std::any a;
assert(!a.has_value());
a.reset();
@@ -39,26 +37,24 @@ int main(int, char**)
}
// small object
{
- small const s(1);
- any a(s);
+ std::any a = small(1);
assert(a.has_value());
a.reset();
assert(!a.has_value());
- a = s;
+ a = small(1);
assert(a.has_value());
}
// large object
{
- large const l(1);
- any a(l);
+ std::any a = large(1);
assert(a.has_value());
a.reset();
assert(!a.has_value());
- a = l;
+ a = large(1);
assert(a.has_value());
}
diff --git a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp
index 3c951f81143d2..3eeb7ea31d00d 100644
--- a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp
@@ -22,25 +22,22 @@
int main(int, char**)
{
- using std::any;
{
- any const a;
+ const std::any a;
assert(a.type() == typeid(void));
ASSERT_NOEXCEPT(a.type());
}
{
- small const s(1);
- any const a(s);
+ std::any a = small(1);
assert(a.type() == typeid(small));
}
{
- large const l(1);
- any const a(l);
+ std::any a = large(1);
assert(a.type() == typeid(large));
}
{
int arr[3];
- any const a(arr);
+ std::any a = arr;
assert(a.type() == typeid(int*)); // ensure that it is decayed
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
index 1a50a694ef8d7..2afac84606486 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
@@ -26,61 +26,58 @@
#include "test_macros.h"
#include "any_helpers.h"
-using std::any;
-using std::any_cast;
-
// Test that the operators are properly noexcept.
void test_cast_is_noexcept() {
- any a;
- ASSERT_NOEXCEPT(any_cast<int>(&a));
+ std::any a;
+ ASSERT_NOEXCEPT(std::any_cast<int>(&a));
- any const& ca = a;
- ASSERT_NOEXCEPT(any_cast<int>(&ca));
+ const std::any& ca = a;
+ ASSERT_NOEXCEPT(std::any_cast<int>(&ca));
}
// Test that the return type of any_cast is correct.
void test_cast_return_type() {
- any a;
- ASSERT_SAME_TYPE(decltype(any_cast<int>(&a)), int*);
- ASSERT_SAME_TYPE(decltype(any_cast<int const>(&a)), int const*);
+ std::any a;
+ ASSERT_SAME_TYPE(decltype(std::any_cast<int>(&a)), int*);
+ ASSERT_SAME_TYPE(decltype(std::any_cast<int const>(&a)), int const*);
- any const& ca = a;
- ASSERT_SAME_TYPE(decltype(any_cast<int>(&ca)), int const*);
- ASSERT_SAME_TYPE(decltype(any_cast<int const>(&ca)), int const*);
+ const std::any& ca = a;
+ ASSERT_SAME_TYPE(decltype(std::any_cast<int>(&ca)), int const*);
+ ASSERT_SAME_TYPE(decltype(std::any_cast<int const>(&ca)), int const*);
}
// Test that any_cast handles null pointers.
void test_cast_nullptr() {
- any* a = nullptr;
- assert(nullptr == any_cast<int>(a));
- assert(nullptr == any_cast<int const>(a));
+ std::any *a = nullptr;
+ assert(nullptr == std::any_cast<int>(a));
+ assert(nullptr == std::any_cast<int const>(a));
- any const* ca = nullptr;
- assert(nullptr == any_cast<int>(ca));
- assert(nullptr == any_cast<int const>(ca));
+ const std::any *ca = nullptr;
+ assert(nullptr == std::any_cast<int>(ca));
+ assert(nullptr == std::any_cast<int const>(ca));
}
// Test casting an empty object.
void test_cast_empty() {
{
- any a;
- assert(nullptr == any_cast<int>(&a));
- assert(nullptr == any_cast<int const>(&a));
+ std::any a;
+ assert(nullptr == std::any_cast<int>(&a));
+ assert(nullptr == std::any_cast<int const>(&a));
- any const& ca = a;
- assert(nullptr == any_cast<int>(&ca));
- assert(nullptr == any_cast<int const>(&ca));
+ const std::any& ca = a;
+ assert(nullptr == std::any_cast<int>(&ca));
+ assert(nullptr == std::any_cast<int const>(&ca));
}
// Create as non-empty, then make empty and run test.
{
- any a(42);
+ std::any a(42);
a.reset();
- assert(nullptr == any_cast<int>(&a));
- assert(nullptr == any_cast<int const>(&a));
+ assert(nullptr == std::any_cast<int>(&a));
+ assert(nullptr == std::any_cast<int const>(&a));
- any const& ca = a;
- assert(nullptr == any_cast<int>(&ca));
- assert(nullptr == any_cast<int const>(&ca));
+ const std::any& ca = a;
+ assert(nullptr == std::any_cast<int>(&ca));
+ assert(nullptr == std::any_cast<int const>(&ca));
}
}
@@ -89,24 +86,24 @@ void test_cast() {
assert(Type::count == 0);
Type::reset();
{
- any a((Type(42)));
- any const& ca = a;
+ std::any a = Type(42);
+ const std::any& ca = a;
assert(Type::count == 1);
assert(Type::copied == 0);
assert(Type::moved == 1);
// Try a cast to a bad type.
// NOTE: Type cannot be an int.
- assert(any_cast<int>(&a) == nullptr);
- assert(any_cast<int const>(&a) == nullptr);
- assert(any_cast<int const volatile>(&a) == nullptr);
+ assert(std::any_cast<int>(&a) == nullptr);
+ assert(std::any_cast<int const>(&a) == nullptr);
+ assert(std::any_cast<int const volatile>(&a) == nullptr);
// Try a cast to the right type, but as a pointer.
- assert(any_cast<Type*>(&a) == nullptr);
- assert(any_cast<Type const*>(&a) == nullptr);
+ assert(std::any_cast<Type*>(&a) == nullptr);
+ assert(std::any_cast<Type const*>(&a) == nullptr);
// Check getting a unqualified type from a non-const any.
- Type* v = any_cast<Type>(&a);
+ Type* v = std::any_cast<Type>(&a);
assert(v != nullptr);
assert(v->value == 42);
@@ -114,19 +111,19 @@ void test_cast() {
v->value = 999;
// Check getting a const qualified type from a non-const any.
- Type const* cv = any_cast<Type const>(&a);
+ Type const* cv = std::any_cast<Type const>(&a);
assert(cv != nullptr);
assert(cv == v);
assert(cv->value == 999);
// Check getting a unqualified type from a const any.
- cv = any_cast<Type>(&ca);
+ cv = std::any_cast<Type>(&ca);
assert(cv != nullptr);
assert(cv == v);
assert(cv->value == 999);
// Check getting a const-qualified type from a const any.
- cv = any_cast<Type const>(&ca);
+ cv = std::any_cast<Type const>(&ca);
assert(cv != nullptr);
assert(cv == v);
assert(cv->value == 999);
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
index 79d9a440dba17..5c7c29fdfeace 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp
@@ -30,64 +30,56 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-using std::bad_any_cast;
-
-
// Test that the operators are NOT marked noexcept.
void test_cast_is_not_noexcept() {
- any a;
- static_assert(!noexcept(any_cast<int>(static_cast<any&>(a))), "");
- static_assert(!noexcept(any_cast<int>(static_cast<any const&>(a))), "");
- static_assert(!noexcept(any_cast<int>(static_cast<any &&>(a))), "");
+ std::any a;
+ static_assert(!noexcept(std::any_cast<int>(static_cast<std::any&>(a))), "");
+ static_assert(!noexcept(std::any_cast<int>(static_cast<std::any const&>(a))), "");
+ static_assert(!noexcept(std::any_cast<int>(static_cast<std::any &&>(a))), "");
}
// Test that the return type of any_cast is correct.
void test_cast_return_type() {
- any a;
- static_assert(std::is_same<decltype(any_cast<int>(a)), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const>(a)), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int&>(a)), int&>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const&>(a)), int const&>::value, "");
-
- static_assert(std::is_same<decltype(any_cast<int&&>(a)), int&&>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const&&>(a)), int const&&>::value, "");
-
- static_assert(std::is_same<decltype(any_cast<int>(std::move(a))), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const>(std::move(a))), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int&>(std::move(a))), int&>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const&>(std::move(a))), int const&>::value, "");
-
- static_assert(std::is_same<decltype(any_cast<int&&>(std::move(a))), int&&>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const&&>(std::move(a))), int const&&>::value, "");
-
- any const& ca = a;
- static_assert(std::is_same<decltype(any_cast<int>(ca)), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const>(ca)), int>::value, "");
- static_assert(std::is_same<decltype(any_cast<int const&>(ca)), int const&>::value, "");
-
- static_assert(std::is_same<decltype(any_cast<int const&&>(ca)), int const&&>::value, "");
+ std::any a;
+ static_assert(std::is_same<decltype(std::any_cast<int>(a)), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const>(a)), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int&>(a)), int&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&>(a)), int const&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int&&>(a)), int&&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&&>(a)), int const&&>::value, "");
+
+ static_assert(std::is_same<decltype(std::any_cast<int>(std::move(a))), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const>(std::move(a))), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int&>(std::move(a))), int&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&>(std::move(a))), int const&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int&&>(std::move(a))), int&&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&&>(std::move(a))), int const&&>::value, "");
+
+ const std::any& ca = a;
+ static_assert(std::is_same<decltype(std::any_cast<int>(ca)), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const>(ca)), int>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&>(ca)), int const&>::value, "");
+ static_assert(std::is_same<decltype(std::any_cast<int const&&>(ca)), int const&&>::value, "");
}
template <class Type, class ConstT = Type>
-void checkThrows(any& a)
+void checkThrows(std::any& a)
{
#if !defined(TEST_HAS_NO_EXCEPTIONS)
try {
- TEST_IGNORE_NODISCARD any_cast<Type>(a);
+ TEST_IGNORE_NODISCARD std::any_cast<Type>(a);
assert(false);
- } catch (bad_any_cast const &) {
- // do nothing
+ } catch (const std::bad_any_cast&) {
+ // do nothing
} catch (...) {
assert(false);
}
try {
- TEST_IGNORE_NODISCARD any_cast<ConstT>(static_cast<any const&>(a));
+ TEST_IGNORE_NODISCARD std::any_cast<ConstT>(static_cast<const std::any&>(a));
assert(false);
- } catch (bad_any_cast const &) {
- // do nothing
+ } catch (const std::bad_any_cast&) {
+ // do nothing
} catch (...) {
assert(false);
}
@@ -98,9 +90,9 @@ void checkThrows(any& a)
typename std::remove_reference<Type>::type&&,
Type
>::type;
- TEST_IGNORE_NODISCARD any_cast<RefType>(static_cast<any&&>(a));
+ TEST_IGNORE_NODISCARD std::any_cast<RefType>(static_cast<std::any&&>(a));
assert(false);
- } catch (bad_any_cast const &) {
+ } catch (const std::bad_any_cast&) {
// do nothing
} catch (...) {
assert(false);
@@ -113,7 +105,7 @@ void checkThrows(any& a)
void test_cast_empty() {
// None of these operations should allocate.
DisableAllocationGuard g; (TEST_IGNORE_NODISCARD g);
- any a;
+ std::any a;
checkThrows<int>(a);
}
@@ -122,8 +114,8 @@ void test_cast_to_reference() {
assert(Type::count == 0);
Type::reset();
{
- any a((Type(42)));
- any const& ca = a;
+ std::any a = Type(42);
+ const std::any& ca = a;
assert(Type::count == 1);
assert(Type::copied == 0);
assert(Type::moved == 1);
@@ -137,47 +129,47 @@ void test_cast_to_reference() {
// Check getting a type by reference from a non-const lvalue any.
{
- Type& v = any_cast<Type&>(a);
+ Type& v = std::any_cast<Type&>(a);
assert(v.value == 42);
- Type const &cv = any_cast<Type const&>(a);
+ Type const &cv = std::any_cast<Type const&>(a);
assert(&cv == &v);
}
// Check getting a type by reference from a const lvalue any.
{
- Type const& v = any_cast<Type const&>(ca);
+ Type const& v = std::any_cast<Type const&>(ca);
assert(v.value == 42);
- Type const &cv = any_cast<Type const&>(ca);
+ Type const &cv = std::any_cast<Type const&>(ca);
assert(&cv == &v);
}
// Check getting a type by reference from a const rvalue any.
{
- Type const& v = any_cast<Type const&>(std::move(ca));
+ Type const& v = std::any_cast<Type const&>(std::move(ca));
assert(v.value == 42);
- Type const &cv = any_cast<Type const&>(std::move(ca));
+ Type const &cv = std::any_cast<Type const&>(std::move(ca));
assert(&cv == &v);
}
// Check getting a type by reference from a const rvalue any.
{
- Type&& v = any_cast<Type&&>(std::move(a));
+ Type&& v = std::any_cast<Type&&>(std::move(a));
assert(v.value == 42);
- assert(any_cast<Type&>(a).value == 42);
+ assert(std::any_cast<Type&>(a).value == 42);
- Type&& cv = any_cast<Type&&>(std::move(a));
+ Type&& cv = std::any_cast<Type&&>(std::move(a));
assert(&cv == &v);
- assert(any_cast<Type&>(a).value == 42);
+ assert(std::any_cast<Type&>(a).value == 42);
}
// Check getting a type by reference from a const rvalue any.
{
- Type const&& v = any_cast<Type const&&>(std::move(a));
+ Type const&& v = std::any_cast<Type const&&>(std::move(a));
assert(v.value == 42);
- assert(any_cast<Type&>(a).value == 42);
+ assert(std::any_cast<Type&>(a).value == 42);
- Type const&& cv = any_cast<Type const&&>(std::move(a));
+ Type const&& cv = std::any_cast<Type const&&>(std::move(a));
assert(&cv == &v);
- assert(any_cast<Type&>(a).value == 42);
+ assert(std::any_cast<Type&>(a).value == 42);
}
// Check that the original object hasn't been changed.
assertContains<Type>(a, 42);
@@ -195,7 +187,7 @@ void test_cast_to_value() {
assert(Type::count == 0);
Type::reset();
{
- any a((Type(42)));
+ std::any a = Type(42);
assert(Type::count == 1);
assert(Type::copied == 0);
assert(Type::moved == 1);
@@ -211,7 +203,7 @@ void test_cast_to_value() {
// Check getting Type by value from a non-const lvalue any.
// This should cause the non-const copy constructor to be called.
{
- Type t = any_cast<Type>(a);
+ Type t = std::any_cast<Type>(a);
assert(Type::count == 2);
assert(Type::copied == 1);
@@ -225,7 +217,7 @@ void test_cast_to_value() {
// Check getting const Type by value from a non-const lvalue any.
// This should cause the const copy constructor to be called.
{
- Type t = any_cast<Type const>(a);
+ Type t = std::any_cast<Type const>(a);
assert(Type::count == 2);
assert(Type::copied == 1);
@@ -239,7 +231,7 @@ void test_cast_to_value() {
// Check getting Type by value from a non-const lvalue any.
// This should cause the const copy constructor to be called.
{
- Type t = any_cast<Type>(static_cast<any const&>(a));
+ Type t = std::any_cast<Type>(static_cast<const std::any&>(a));
assert(Type::count == 2);
assert(Type::copied == 1);
@@ -253,7 +245,7 @@ void test_cast_to_value() {
// Check getting Type by value from a non-const rvalue any.
// This should cause the non-const copy constructor to be called.
{
- Type t = any_cast<Type>(static_cast<any &&>(a));
+ Type t = std::any_cast<Type>(static_cast<std::any&&>(a));
assert(Type::count == 2);
assert(Type::moved == 1);
@@ -261,15 +253,15 @@ void test_cast_to_value() {
assert(Type::const_copied == 0);
assert(Type::non_const_copied == 0);
assert(t.value == 42);
- assert(any_cast<Type&>(a).value == 0);
- any_cast<Type&>(a).value = 42; // reset the value
+ assert(std::any_cast<Type&>(a).value == 0);
+ std::any_cast<Type&>(a).value = 42; // reset the value
}
assert(Type::count == 1);
Type::reset();
// Check getting const Type by value from a non-const rvalue any.
// This should cause the const copy constructor to be called.
{
- Type t = any_cast<Type const>(static_cast<any &&>(a));
+ Type t = std::any_cast<Type const>(static_cast<std::any&&>(a));
assert(Type::count == 2);
assert(Type::copied == 0);
@@ -277,15 +269,15 @@ void test_cast_to_value() {
assert(Type::non_const_copied == 0);
assert(Type::moved == 1);
assert(t.value == 42);
- assert(any_cast<Type&>(a).value == 0);
- any_cast<Type&>(a).value = 42; // reset the value
+ assert(std::any_cast<Type&>(a).value == 0);
+ std::any_cast<Type&>(a).value = 42; // reset the value
}
assert(Type::count == 1);
Type::reset();
// Check getting Type by value from a const rvalue any.
// This should cause the const copy constructor to be called.
{
- Type t = any_cast<Type>(static_cast<any const&&>(a));
+ Type t = std::any_cast<Type>(static_cast<const std::any&&>(a));
assert(Type::count == 2);
assert(Type::copied == 1);
@@ -293,7 +285,7 @@ void test_cast_to_value() {
assert(Type::non_const_copied == 0);
assert(Type::moved == 0);
assert(t.value == 42);
- assert(any_cast<Type&>(a).value == 42);
+ assert(std::any_cast<Type&>(a).value == 42);
}
// Ensure we still only have 1 Type object alive.
assert(Type::count == 1);
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp
index 73cdad798cfbe..cd70bbe9c3218 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp
@@ -21,43 +21,41 @@
#include <any>
struct TestType {};
-using std::any;
-using std::any_cast;
void test_const_lvalue_cast_request_non_const_lvalue()
{
- const any a;
+ const std::any a;
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
// expected-error at any:* {{drops 'const' qualifier}}
- any_cast<TestType &>(a); // expected-note {{requested here}}
+ std::any_cast<TestType &>(a); // expected-note {{requested here}}
- const any a2(42);
+ const std::any a2(42);
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
// expected-error at any:* {{drops 'const' qualifier}}
- any_cast<int&>(a2); // expected-note {{requested here}}
+ std::any_cast<int&>(a2); // expected-note {{requested here}}
}
void test_lvalue_any_cast_request_rvalue()
{
- any a;
+ std::any a;
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an lvalue reference or a CopyConstructible type"}}
- any_cast<TestType &&>(a); // expected-note {{requested here}}
+ std::any_cast<TestType &&>(a); // expected-note {{requested here}}
- any a2(42);
+ std::any a2(42);
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an lvalue reference or a CopyConstructible type"}}
- any_cast<int&&>(a2); // expected-note {{requested here}}
+ std::any_cast<int&&>(a2); // expected-note {{requested here}}
}
void test_rvalue_any_cast_request_lvalue()
{
- any a;
+ std::any a;
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an rvalue reference or a CopyConstructible type"}}
// expected-error at any:* {{non-const lvalue reference to type 'TestType' cannot bind to a temporary}}
- any_cast<TestType &>(std::move(a)); // expected-note {{requested here}}
+ std::any_cast<TestType &>(std::move(a)); // expected-note {{requested here}}
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an rvalue reference or a CopyConstructible type"}}
// expected-error at any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
- any_cast<int&>(42);
+ std::any_cast<int&>(42);
}
int main(int, char**)
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
index a28e3fc9d1d78..d9d75bcc35fce 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
@@ -32,22 +32,19 @@ struct TestType2 {};
int main(int, char**)
{
- using std::any;
- using std::any_cast;
-
- any a;
+ std::any a;
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
- any_cast<TestType &>(static_cast<any const&>(a)); // expected-note {{requested here}}
+ std::any_cast<TestType &>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
- any_cast<TestType &&>(static_cast<any const&>(a)); // expected-note {{requested here}}
+ std::any_cast<TestType &&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
- any_cast<TestType2 &>(static_cast<any const&&>(a)); // expected-note {{requested here}}
+ std::any_cast<TestType2 &>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
- any_cast<TestType2 &&>(static_cast<any const&&>(a)); // expected-note {{requested here}}
+ std::any_cast<TestType2 &&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
return 0;
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
index ec40eeeec11b4..7ff475b9a0f63 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
@@ -33,9 +33,6 @@
#include <any>
-using std::any;
-using std::any_cast;
-
struct no_copy
{
no_copy() {}
@@ -50,17 +47,17 @@ struct no_move {
};
int main(int, char**) {
- any a;
+ std::any a;
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an lvalue reference or a CopyConstructible type"}}
- any_cast<no_copy>(static_cast<any&>(a)); // expected-note {{requested here}}
+ std::any_cast<no_copy>(static_cast<std::any&>(a)); // expected-note {{requested here}}
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
- any_cast<no_copy>(static_cast<any const&>(a)); // expected-note {{requested here}}
+ std::any_cast<no_copy>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
- any_cast<no_copy>(static_cast<any &&>(a)); // OK
+ std::any_cast<no_copy>(static_cast<std::any &&>(a)); // OK
// expected-error-re at any:* {{static_assert failed{{.*}} "ValueType is required to be an rvalue reference or a CopyConstructible type"}}
- any_cast<no_move>(static_cast<any &&>(a));
+ std::any_cast<no_move>(static_cast<std::any &&>(a));
return 0;
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp
index 9f5fa607fede4..db89641a361fb 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp
@@ -18,38 +18,35 @@
#include <any>
-using std::any;
-using std::any_cast;
-
int main(int, char**)
{
- any a(1);
+ std::any a = 1;
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int &>(&a); // expected-note {{requested here}}
+ std::any_cast<int &>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int &&>(&a); // expected-note {{requested here}}
+ std::any_cast<int &&>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int const &>(&a); // expected-note {{requested here}}
+ std::any_cast<int const &>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int const&&>(&a); // expected-note {{requested here}}
+ std::any_cast<int const&&>(&a); // expected-note {{requested here}}
- any const& a2 = a;
+ const std::any& a2 = a;
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int &>(&a2); // expected-note {{requested here}}
+ std::any_cast<int &>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int &&>(&a2); // expected-note {{requested here}}
+ std::any_cast<int &&>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int const &>(&a2); // expected-note {{requested here}}
+ std::any_cast<int const &>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}}
- any_cast<int const &&>(&a2); // expected-note {{requested here}}
+ std::any_cast<int const &&>(&a2); // expected-note {{requested here}}
return 0;
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp
index 6b8f93073b030..987b387581235 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp
@@ -24,10 +24,6 @@
#include "count_new.h"
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
-
template <class Type>
void test_make_any_type() {
// constructing from a small type should perform no allocations.
@@ -35,7 +31,7 @@ void test_make_any_type() {
assert(Type::count == 0);
Type::reset();
{
- any a = std::make_any<Type>();
+ std::any a = std::make_any<Type>();
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -45,7 +41,7 @@ void test_make_any_type() {
assert(Type::count == 0);
Type::reset();
{
- any a = std::make_any<Type>(101);
+ std::any a = std::make_any<Type>(101);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -55,7 +51,7 @@ void test_make_any_type() {
assert(Type::count == 0);
Type::reset();
{
- any a = std::make_any<Type>(-1, 42, -1);
+ std::any a = std::make_any<Type>(-1, 42, -1);
assert(Type::count == 1);
assert(Type::copied == 0);
@@ -71,21 +67,21 @@ void test_make_any_type_tracked() {
// constructing from a small type should perform no allocations.
DisableAllocationGuard g(isSmallType<Type>()); ((void)g);
{
- any a = std::make_any<Type>();
+ std::any a = std::make_any<Type>();
assertArgsMatch<Type>(a);
}
{
- any a = std::make_any<Type>(-1, 42, -1);
+ std::any a = std::make_any<Type>(-1, 42, -1);
assertArgsMatch<Type, int, int, int>(a);
}
// initializer_list constructor tests
{
- any a = std::make_any<Type>({-1, 42, -1});
+ std::any a = std::make_any<Type>({-1, 42, -1});
assertArgsMatch<Type, std::initializer_list<int>>(a);
}
{
int x = 42;
- any a = std::make_any<Type>({-1, 42, -1}, x);
+ std::any a = std::make_any<Type>({-1, 42, -1}, x);
assertArgsMatch<Type, std::initializer_list<int>, int&>(a);
}
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp
index 440159f12d72f..d372b7124f0ae 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp
@@ -22,24 +22,21 @@
#include "test_macros.h"
-using std::any;
-using std::any_cast;
-
int main(int, char**)
{
{ // test noexcept
- any a;
+ std::any a;
static_assert(noexcept(swap(a, a)), "swap(any&, any&) must be noexcept");
}
{
- any a1(1);
- any a2(2);
+ std::any a1 = 1;
+ std::any a2 = 2;
swap(a1, a2);
- assert(any_cast<int>(a1) == 2);
- assert(any_cast<int>(a2) == 1);
+ assert(std::any_cast<int>(a1) == 2);
+ assert(std::any_cast<int>(a2) == 1);
}
return 0;
More information about the libcxx-commits
mailing list