diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// reference& operator=(bool) + +#include +#include + +bool test() { + std::vector vec; + typedef std::vector::reference Ref; + vec.push_back(true); + vec.push_back(false); + Ref ref = vec[0]; + const Ref cref = vec[0]; + + assert(ref); + ref = false; + assert(!vec[0]); + assert(!vec[1]); + ref = true; + assert(vec[0]); + assert(!vec[1]); + + assert(cref); + + return true; +} + +int main(int, char**) { + test(); + + return 0; +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// reference& operator=(const reference&) + +#include +#include + +bool test() { + std::vector vec; + typedef std::vector::reference Ref; + vec.push_back(true); + vec.push_back(false); + Ref ref1 = vec[0]; + Ref ref2 = vec[1]; + ref2 = ref1; + // Ref& + { + vec[0] = false; + vec[1] = true; + ref1 = ref2; + assert(vec[0]); + assert(vec[1]); + } + { + vec[0] = true; + vec[1] = false; + ref1 = ref2; + assert(!vec[0]); + assert(!vec[1]); + } + // Ref&& + { + vec[0] = false; + vec[1] = true; + ref1 = std::move(ref2); + assert(vec[0]); + assert(vec[1]); + } + { + vec[0] = true; + vec[1] = false; + ref1 = std::move(ref2); + assert(!vec[0]); + assert(!vec[1]); + } + // const Ref& + { + vec[0] = false; + vec[1] = true; + ref1 = static_cast(ref2); + assert(vec[0]); + assert(vec[1]); + } + { + vec[0] = true; + vec[1] = false; + ref1 = static_cast(ref2); + assert(!vec[0]); + assert(!vec[1]); + } + return true; +} + +int main(int, char**) { + test(); + + return 0; +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// reference(const reference&) + +#include +#include + +bool test() { + std::vector vec; + typedef std::vector::reference Ref; + vec.push_back(true); + Ref ref = vec[0]; + Ref ref2 = ref; + assert(ref == ref2 && ref2); + ref.flip(); + assert(ref == ref2 && !ref2); + + return true; +} + +int main(int, char**) { + test(); + + return 0; +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// flip() + +#include +#include + +bool test() { + std::vector vec; + typedef std::vector::reference Ref; + vec.push_back(true); + vec.push_back(false); + Ref ref = vec[0]; + assert(vec[0]); + assert(!vec[1]); + ref.flip(); + assert(!vec[0]); + assert(!vec[1]); + ref.flip(); + assert(vec[0]); + assert(!vec[1]); + + return true; +} + +int main(int, char**) { + test(); + + return 0; +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// operator bool() + +#include +#include +#include + +bool test() { + std::vector vec; + typedef std::vector::reference Ref; + static_assert(std::is_convertible::value, ""); + + vec.push_back(true); + vec.push_back(false); + Ref true_ref = vec[0]; + Ref false_ref = vec[1]; + bool b = true_ref; + assert(b); + assert(true_ref); + assert(!false_ref); + + return true; +} + +int main(int, char**) { + test(); + + return 0; +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "test_macros.h" + +using Ref = std::vector::reference; + +LIBCPP_STATIC_ASSERT(!std::is_trivially_constructible::value, ""); +LIBCPP_STATIC_ASSERT(std::is_trivially_copy_constructible::value, ""); +LIBCPP_STATIC_ASSERT(std::is_trivially_move_constructible::value, ""); +LIBCPP_STATIC_ASSERT(!std::is_trivially_copy_assignable::value, ""); +LIBCPP_STATIC_ASSERT(!std::is_trivially_move_assignable::value, ""); +LIBCPP_STATIC_ASSERT(std::is_trivially_destructible::value, "");