-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx] makes
pair
conditionally trivially copyable for C++20
`pair` can have trivial copy and move assignment operators when both its members have trivial copy and move operators, which opens `pair` up to being trivially copyable. This is the first of three possible commits to bring users a more robust implementation. It's currently unclear how to implement this without using a _requires-clause_, so the feature is restricted to C++20 for now. There has also been some interest in moving this out of the unstable ABI mode. Both of these changes are intended to arrive in future pull requests, should their feasibility pan out.
- Loading branch information
Showing
6 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libcxx/test/std/utilities/utility/pairs/pairs.pair/trivially_copyable.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// <utility> | ||
|
||
// template <class T1, class T2> struct pair | ||
|
||
// Checks that `std::pair` is actually trivially copyable. | ||
|
||
#include <type_traits> | ||
#include <utility> | ||
|
||
#if defined(_LIBCPP_ABI_PAIR_TRIVIALLY_COPYABLE) | ||
static_assert(std::is_trivially_copyable_v<std::pair<int, int>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<int, int const>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<int const, int>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<int const, int const>>); | ||
|
||
static_assert(!std::is_trivially_copyable_v<std::pair<int, int&>>); | ||
static_assert(!std::is_trivially_copyable_v<std::pair<int&, int>>); | ||
static_assert(!std::is_trivially_copyable_v<std::pair<int&, int&>>); | ||
|
||
enum E {}; | ||
static_assert(std::is_trivially_copyable_v<std::pair<E, E>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E, E const>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E const, E>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E const, E const>>); | ||
|
||
static_assert(std::is_trivially_copyable_v<std::pair<E, int>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E, int const>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E const, int>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<E const, int const>>); | ||
|
||
struct S {}; | ||
static_assert(std::is_trivially_copyable_v<std::pair<S, S>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<S, int>>); | ||
static_assert(std::is_trivially_copyable_v<std::pair<S, E>>); | ||
#endif |