2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_TUPLE
|
|
|
|
#define _LIBCPP_TUPLE
|
|
|
|
|
|
|
|
/*
|
|
|
|
tuple synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class... T>
|
|
|
|
class tuple {
|
|
|
|
public:
|
2019-09-26 22:51:10 +08:00
|
|
|
explicit(see-below) constexpr tuple();
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(const T&...); // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... U>
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(U&&...); // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
tuple(const tuple&) = default;
|
2011-05-28 03:08:18 +08:00
|
|
|
tuple(tuple&&) = default;
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
|
|
|
|
template<class... UTypes>
|
|
|
|
constexpr explicit(see-below) tuple(tuple<UTypes...>&); // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... U>
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... U>
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class... UTypes>
|
|
|
|
constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23
|
|
|
|
|
|
|
|
template<class U1, class U2>
|
|
|
|
constexpr explicit(see-below) tuple(pair<U1, U2>&); // iff sizeof...(Types) == 2 // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class U1, class U2>
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class U1, class U2>
|
2019-07-23 04:45:23 +08:00
|
|
|
explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class U1, class U2>
|
|
|
|
constexpr explicit(see-below) tuple(const pair<U1, U2>&&); // iff sizeof...(Types) == 2 // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// allocator-extended constructors
|
|
|
|
template <class Alloc>
|
|
|
|
tuple(allocator_arg_t, const Alloc& a);
|
|
|
|
template <class Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc, class... U>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class Alloc, class... UTypes>
|
|
|
|
constexpr explicit(see-below)
|
2022-06-27 21:36:52 +08:00
|
|
|
tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&); // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc, class... U>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc, class... U>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class Alloc, class... UTypes>
|
|
|
|
constexpr explicit(see-below)
|
|
|
|
tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&); // C++23
|
|
|
|
template<class Alloc, class U1, class U2>
|
|
|
|
constexpr explicit(see-below)
|
|
|
|
tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&); // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc, class U1, class U2>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Alloc, class U1, class U2>
|
2021-02-10 08:12:16 +08:00
|
|
|
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class Alloc, class U1, class U2>
|
|
|
|
constexpr explicit(see-below)
|
|
|
|
tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&); // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(const tuple&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
constexpr const tuple& operator=(const tuple&) const; // C++23
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
constexpr const tuple& operator=(tuple&&) const; // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... U>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(const tuple<U...>&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class... UTypes>
|
|
|
|
constexpr const tuple& operator=(const tuple<UTypes...>&) const; // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... U>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(tuple<U...>&&); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class... UTypes>
|
|
|
|
constexpr const tuple& operator=(tuple<UTypes...>&&) const; // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class U1, class U2>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class U1, class U2>
|
|
|
|
constexpr const tuple& operator=(const pair<U1, U2>&) const; // iff sizeof...(Types) == 2 // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class U1, class U2>
|
2021-02-10 08:12:16 +08:00
|
|
|
tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class U1, class U2>
|
|
|
|
constexpr const tuple& operator=(pair<U1, U2>&&) const; // iff sizeof...(Types) == 2 // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-07-31 23:56:20 +08:00
|
|
|
template<class U, size_t N>
|
|
|
|
tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
|
|
|
|
template<class U, size_t N>
|
|
|
|
tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
|
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
constexpr void swap(const tuple&) const noexcept(see-below); // C++23
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2022-01-18 02:45:42 +08:00
|
|
|
|
|
|
|
template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
|
|
|
|
requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
|
|
|
|
struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
|
|
|
|
using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class... TTypes, class... UTypes> // since C++23
|
|
|
|
requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
|
|
|
|
struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
|
|
|
|
using type = tuple<common_type_t<TTypes, UTypes>...>;
|
|
|
|
};
|
|
|
|
|
2019-08-13 02:30:31 +08:00
|
|
|
template <class ...T>
|
|
|
|
tuple(T...) -> tuple<T...>; // since C++17
|
|
|
|
template <class T1, class T2>
|
|
|
|
tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
|
|
|
|
template <class Alloc, class ...T>
|
|
|
|
tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
|
|
|
|
template <class Alloc, class T1, class T2>
|
|
|
|
tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
|
|
|
|
template <class Alloc, class ...T>
|
|
|
|
tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
|
|
|
|
|
2018-01-03 01:17:01 +08:00
|
|
|
inline constexpr unspecified ignore;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-07-23 00:02:19 +08:00
|
|
|
template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
|
2013-10-06 02:46:37 +08:00
|
|
|
template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
|
2014-02-26 00:11:46 +08:00
|
|
|
template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
|
2013-07-23 00:02:19 +08:00
|
|
|
template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
|
2016-07-18 08:35:56 +08:00
|
|
|
|
|
|
|
// [tuple.apply], calling a function with a tuple of arguments:
|
|
|
|
template <class F, class Tuple>
|
|
|
|
constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
|
|
|
|
template <class T, class Tuple>
|
|
|
|
constexpr T make_from_tuple(Tuple&& t); // C++17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// 20.4.1.4, tuple helper classes:
|
2019-01-12 05:57:12 +08:00
|
|
|
template <class T> struct tuple_size; // undefined
|
|
|
|
template <class... T> struct tuple_size<tuple<T...>>;
|
2016-07-18 08:35:56 +08:00
|
|
|
template <class T>
|
2018-01-03 01:17:01 +08:00
|
|
|
inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
|
2019-04-02 00:39:34 +08:00
|
|
|
template <size_t I, class T> struct tuple_element; // undefined
|
|
|
|
template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
|
2015-11-20 03:45:29 +08:00
|
|
|
template <size_t I, class T>
|
|
|
|
using tuple_element_t = typename tuple_element <I, T>::type; // C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// 20.4.1.5, element access:
|
2015-11-20 03:45:29 +08:00
|
|
|
template <size_t I, class... T>
|
2011-05-28 03:08:18 +08:00
|
|
|
typename tuple_element<I, tuple<T...>>::type&
|
2013-07-18 02:25:36 +08:00
|
|
|
get(tuple<T...>&) noexcept; // constexpr in C++14
|
2015-11-20 03:45:29 +08:00
|
|
|
template <size_t I, class... T>
|
|
|
|
const typename tuple_element<I, tuple<T...>>::type&
|
2013-07-18 02:25:36 +08:00
|
|
|
get(const tuple<T...>&) noexcept; // constexpr in C++14
|
2015-11-20 03:45:29 +08:00
|
|
|
template <size_t I, class... T>
|
2011-05-28 03:08:18 +08:00
|
|
|
typename tuple_element<I, tuple<T...>>::type&&
|
2013-07-18 02:25:36 +08:00
|
|
|
get(tuple<T...>&&) noexcept; // constexpr in C++14
|
2015-12-18 08:36:55 +08:00
|
|
|
template <size_t I, class... T>
|
|
|
|
const typename tuple_element<I, tuple<T...>>::type&&
|
|
|
|
get(const tuple<T...>&&) noexcept; // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-07-13 10:54:05 +08:00
|
|
|
template <class T1, class... T>
|
|
|
|
constexpr T1& get(tuple<T...>&) noexcept; // C++14
|
|
|
|
template <class T1, class... T>
|
2015-11-20 03:45:29 +08:00
|
|
|
constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
|
2013-07-13 10:54:05 +08:00
|
|
|
template <class T1, class... T>
|
|
|
|
constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
|
2015-12-18 08:36:55 +08:00
|
|
|
template <class T1, class... T>
|
|
|
|
constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
|
2013-07-13 10:54:05 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// 20.4.1.6, relational operators:
|
2013-07-23 00:02:19 +08:00
|
|
|
template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
|
2021-10-09 05:54:28 +08:00
|
|
|
template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
|
|
|
|
template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
|
|
|
|
template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
|
|
|
|
template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
|
|
|
|
template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
|
|
|
|
template<class... T, class... U>
|
|
|
|
constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
|
|
|
|
operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class... Types, class Alloc>
|
|
|
|
struct uses_allocator<tuple<Types...>, Alloc>;
|
|
|
|
|
|
|
|
template <class... Types>
|
2011-05-28 03:08:18 +08:00
|
|
|
void
|
|
|
|
swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
|
2010-05-12 03:42:16 +08:00
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template <class... Types>
|
|
|
|
constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2021-10-09 05:54:28 +08:00
|
|
|
#include <__compare/common_comparison_category.h>
|
|
|
|
#include <__compare/synth_three_way.h>
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <__config>
|
2021-06-10 07:10:17 +08:00
|
|
|
#include <__functional/unwrap_ref.h>
|
2021-07-01 21:25:35 +08:00
|
|
|
#include <__memory/allocator_arg_t.h>
|
|
|
|
#include <__memory/uses_allocator.h>
|
|
|
|
#include <__tuple>
|
2021-06-05 10:47:47 +08:00
|
|
|
#include <__utility/forward.h>
|
2021-10-09 05:54:28 +08:00
|
|
|
#include <__utility/integer_sequence.h>
|
2021-06-05 10:47:47 +08:00
|
|
|
#include <__utility/move.h>
|
2022-03-06 02:17:07 +08:00
|
|
|
#include <__utility/pair.h>
|
|
|
|
#include <__utility/piecewise_construct.h>
|
|
|
|
#include <__utility/swap.h>
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <type_traits>
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
[libc++] Re-add transitive includes that had been removed since LLVM 14
This commit re-adds transitive includes that had been removed by
4cd04d1687f1, c36870c8e79c, a83f4b9cda57, 1458458b558d, 2e2f3158c604,
and 489637e66dd3. This should cover almost all the includes that had
been removed since LLVM 14 and that would contribute to breaking user
code when releasing LLVM 15.
It is possible to disable the inclusion of these headers by defining
_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will
enable that macro and start fixing downstream issues immediately. We
can then remove the macro (and the transitive includes) by default in
a future release. That way, we will break users only once by removing
transitive includes in bulk instead of doing it bit by bit a every
release, which is more disruptive for users.
Note 1: The set of headers to re-add was found by re-generating the
transitive include test on a checkout of release/14.x, which
provided the list of all transitive includes we used to provide.
Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map>
have been added in this commit. These transitive inclusions were
added when we implemented boyer_moore_searcher in <functional>.
Note 3: This is a best effort patch to try and resolve downstream breakage
caused since branching LLVM 14. I wasn't able to perfectly mirror
transitive includes in LLVM 14 for a few headers, so I added a
release note explaining it. To summarize, adding boyer_moore_searcher
created a bunch of circular dependencies, so we have to break
backwards compatibility in a few cases.
Differential Revision: https://reviews.llvm.org/D128661
2022-06-28 03:53:41 +08:00
|
|
|
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
|
|
|
|
# include <exception>
|
|
|
|
# include <iosfwd>
|
|
|
|
# include <new>
|
|
|
|
# include <typeinfo>
|
|
|
|
# include <utility>
|
|
|
|
#endif
|
|
|
|
|
2022-06-17 04:43:46 +08:00
|
|
|
// standard-mandated includes
|
|
|
|
#include <compare>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-03-03 14:18:11 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// __tuple_leaf
|
|
|
|
|
2015-06-13 15:08:02 +08:00
|
|
|
template <size_t _Ip, class _Hp,
|
|
|
|
bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
|
2011-12-12 04:31:33 +08:00
|
|
|
>
|
2010-05-12 03:42:16 +08:00
|
|
|
class __tuple_leaf;
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Hp, bool _Ep>
|
2021-02-10 08:12:16 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
|
2011-05-28 03:08:18 +08:00
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
swap(__x.get(), __y.get());
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template <size_t _Ip, class _Hp, bool _Ep>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2022-06-27 21:36:52 +08:00
|
|
|
void swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, const __tuple_leaf<_Ip, _Hp, _Ep>& __y)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<const _Hp>::value) {
|
|
|
|
swap(__x.get(), __y.get());
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <size_t _Ip, class _Hp, bool>
|
|
|
|
class __tuple_leaf
|
|
|
|
{
|
2017-06-01 10:14:21 +08:00
|
|
|
_Hp __value_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-20 10:57:39 +08:00
|
|
|
template <class _Tp>
|
|
|
|
static constexpr bool __can_bind_reference() {
|
[libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=20855
Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:
```
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
```
However, we are over-aggressive and we incorrectly diagnose cases such as:
```
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
```
This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:
```
std::tuple<int, const std::string&> t(42, "abc");
```
Reviewers: rsmith, mclow.lists
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41977
llvm-svn: 323380
2018-01-25 06:14:01 +08:00
|
|
|
#if __has_keyword(__reference_binds_to_temporary)
|
|
|
|
return !__reference_binds_to_temporary(_Hp, _Tp);
|
2018-01-25 07:10:02 +08:00
|
|
|
#else
|
|
|
|
return true;
|
[libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=20855
Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:
```
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
```
However, we are over-aggressive and we incorrectly diagnose cases such as:
```
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
```
This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:
```
std::tuple<int, const std::string&> t(42, "abc");
```
Reviewers: rsmith, mclow.lists
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41977
llvm-svn: 323380
2018-01-25 06:14:01 +08:00
|
|
|
#endif
|
2016-07-20 10:57:39 +08:00
|
|
|
}
|
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf& operator=(const __tuple_leaf&);
|
|
|
|
public:
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
|
2017-06-01 10:14:21 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
|
2010-05-12 03:42:16 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 0>, const _Alloc&)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_()
|
2010-05-12 03:42:16 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(allocator_arg_t(), __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(__a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
|
2010-09-28 01:54:17 +08:00
|
|
|
template <class _Tp,
|
2021-09-08 21:14:43 +08:00
|
|
|
class = __enable_if_t<
|
2019-06-24 04:28:29 +08:00
|
|
|
_And<
|
|
|
|
_IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
|
|
|
|
is_constructible<_Hp, _Tp>
|
2014-07-25 02:48:34 +08:00
|
|
|
>::value
|
2019-06-24 04:28:29 +08:00
|
|
|
>
|
2014-07-25 02:48:34 +08:00
|
|
|
>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2012-07-07 05:53:48 +08:00
|
|
|
explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(_VSTD::forward<_Tp>(__t))
|
[libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=20855
Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:
```
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
```
However, we are over-aggressive and we incorrectly diagnose cases such as:
```
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
```
This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:
```
std::tuple<int, const std::string&> t(42, "abc");
```
Reviewers: rsmith, mclow.lists
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41977
llvm-svn: 323380
2018-01-25 06:14:01 +08:00
|
|
|
{static_assert(__can_bind_reference<_Tp&&>(),
|
|
|
|
"Attempted construction of reference element binds to a temporary whose lifetime has ended");}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(_VSTD::forward<_Tp>(__t))
|
[libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=20855
Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:
```
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
```
However, we are over-aggressive and we incorrectly diagnose cases such as:
```
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
```
This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:
```
std::tuple<int, const std::string&> t(42, "abc");
```
Reviewers: rsmith, mclow.lists
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41977
llvm-svn: 323380
2018-01-25 06:14:01 +08:00
|
|
|
{static_assert(__can_bind_reference<_Tp&&>(),
|
|
|
|
"Attempted construction of reference element binds to a temporary whose lifetime has ended");}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
|
2016-07-20 10:57:39 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to uses-allocator construct a reference element in a tuple");}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __value_(_VSTD::forward<_Tp>(__t), __a)
|
2016-07-20 10:57:39 +08:00
|
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
|
|
"Attempted to uses-allocator construct a reference element in a tuple");}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-04-22 07:48:09 +08:00
|
|
|
__tuple_leaf(const __tuple_leaf& __t) = default;
|
|
|
|
__tuple_leaf(__tuple_leaf&& __t) = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-05-28 03:08:18 +08:00
|
|
|
int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(*this, __t);
|
2010-05-12 03:42:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
int swap(const __tuple_leaf& __t) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
|
|
|
|
_VSTD::swap(*this, __t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-01 10:14:21 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Hp>
|
|
|
|
class __tuple_leaf<_Ip, _Hp, true>
|
|
|
|
: private _Hp
|
|
|
|
{
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf& operator=(const __tuple_leaf&);
|
|
|
|
public:
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
|
2012-07-07 04:50:27 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
|
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
|
|
|
|
: _Hp(allocator_arg_t(), __a) {}
|
|
|
|
|
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
|
|
|
|
: _Hp(__a) {}
|
|
|
|
|
2010-09-28 01:54:17 +08:00
|
|
|
template <class _Tp,
|
2021-09-08 21:14:43 +08:00
|
|
|
class = __enable_if_t<
|
2019-06-24 04:28:29 +08:00
|
|
|
_And<
|
|
|
|
_IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
|
|
|
|
is_constructible<_Hp, _Tp>
|
|
|
|
>::value
|
|
|
|
>
|
2014-07-25 02:48:34 +08:00
|
|
|
>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2012-07-07 05:53:48 +08:00
|
|
|
explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
|
2011-07-01 05:18:19 +08:00
|
|
|
: _Hp(_VSTD::forward<_Tp>(__t)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
|
2011-07-01 05:18:19 +08:00
|
|
|
: _Hp(_VSTD::forward<_Tp>(__t)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
|
2011-07-01 05:18:19 +08:00
|
|
|
: _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
|
2011-07-01 05:18:19 +08:00
|
|
|
: _Hp(_VSTD::forward<_Tp>(__t), __a) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-07-25 02:48:34 +08:00
|
|
|
__tuple_leaf(__tuple_leaf const &) = default;
|
|
|
|
__tuple_leaf(__tuple_leaf &&) = default;
|
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-05-28 03:08:18 +08:00
|
|
|
int
|
|
|
|
swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(*this, __t);
|
2010-05-12 03:42:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
int swap(const __tuple_leaf& __rhs) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
|
|
|
|
_VSTD::swap(*this, __rhs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-09-24 02:58:28 +08:00
|
|
|
template <class ..._Tp>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2012-07-07 05:53:48 +08:00
|
|
|
void __swallow(_Tp&&...) _NOEXCEPT {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-10-15 18:33:02 +08:00
|
|
|
template <class _Tp>
|
|
|
|
struct __all_default_constructible;
|
2011-05-28 03:08:18 +08:00
|
|
|
|
2014-10-15 18:33:02 +08:00
|
|
|
template <class ..._Tp>
|
|
|
|
struct __all_default_constructible<__tuple_types<_Tp...>>
|
|
|
|
: __all<is_default_constructible<_Tp>::value...>
|
|
|
|
{ };
|
2011-05-28 03:08:18 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// __tuple_impl
|
|
|
|
|
|
|
|
template<class _Indx, class ..._Tp> struct __tuple_impl;
|
|
|
|
|
|
|
|
template<size_t ..._Indx, class ..._Tp>
|
2017-01-17 05:15:08 +08:00
|
|
|
struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
|
2010-05-12 03:42:16 +08:00
|
|
|
: public __tuple_leaf<_Indx, _Tp>...
|
|
|
|
{
|
2012-07-07 04:39:45 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2021-02-10 08:12:16 +08:00
|
|
|
constexpr __tuple_impl()
|
2012-07-07 04:50:27 +08:00
|
|
|
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
|
2012-07-07 04:39:45 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <size_t ..._Uf, class ..._Tf,
|
|
|
|
size_t ..._Ul, class ..._Tl, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit
|
|
|
|
__tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
|
|
|
|
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
|
2012-07-07 05:53:48 +08:00
|
|
|
_Up&&... __u)
|
|
|
|
_NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
|
|
|
|
__all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
|
2011-07-01 05:18:19 +08:00
|
|
|
__tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf<_Ul, _Tl>()...
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <class _Alloc, size_t ..._Uf, class ..._Tf,
|
|
|
|
size_t ..._Ul, class ..._Tl, class ..._Up>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit
|
|
|
|
__tuple_impl(allocator_arg_t, const _Alloc& __a,
|
|
|
|
__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
|
|
|
|
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
|
|
|
|
_Up&&... __u) :
|
|
|
|
__tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Up>(__u))...,
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <class _Tuple,
|
2022-07-04 07:21:44 +08:00
|
|
|
class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
|
2010-05-12 03:42:16 +08:00
|
|
|
>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2012-07-07 05:53:48 +08:00
|
|
|
__tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
|
|
|
|
typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
|
2011-07-01 05:18:19 +08:00
|
|
|
: __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
|
|
|
|
typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
template <class _Alloc, class _Tuple,
|
2022-07-04 07:21:44 +08:00
|
|
|
class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
|
2010-05-12 03:42:16 +08:00
|
|
|
>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
__tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
|
|
|
|
: __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
|
2010-08-22 08:02:43 +08:00
|
|
|
typename __make_tuple_types<_Tuple>::type>::type>(), __a,
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<typename tuple_element<_Indx,
|
|
|
|
typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
|
2013-11-07 01:45:43 +08:00
|
|
|
__tuple_impl(const __tuple_impl&) = default;
|
|
|
|
__tuple_impl(__tuple_impl&&) = default;
|
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
void swap(__tuple_impl& __t)
|
2011-05-28 03:08:18 +08:00
|
|
|
_NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2018-07-31 23:56:20 +08:00
|
|
|
_VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
void swap(const __tuple_impl& __t) const
|
|
|
|
_NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value)
|
|
|
|
{
|
|
|
|
_VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2018-07-31 23:56:20 +08:00
|
|
|
template<class _Dest, class _Source, size_t ..._Np>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2018-07-31 23:56:20 +08:00
|
|
|
void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
|
|
|
|
_VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
|
|
|
|
}
|
2016-04-16 02:05:59 +08:00
|
|
|
|
2018-07-31 23:56:20 +08:00
|
|
|
template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2018-07-31 23:56:20 +08:00
|
|
|
void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
|
|
|
|
_VSTD::__swallow(((
|
2021-02-25 03:53:21 +08:00
|
|
|
_VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
|
2018-07-31 23:56:20 +08:00
|
|
|
), void(), 0)...);
|
|
|
|
}
|
2016-04-16 02:05:59 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ..._Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS tuple
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2017-06-01 10:14:21 +08:00
|
|
|
typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 10:14:21 +08:00
|
|
|
_BaseT __base_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-07-18 02:25:36 +08:00
|
|
|
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-12-02 04:21:04 +08:00
|
|
|
typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
|
2013-07-18 02:25:36 +08:00
|
|
|
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-12-02 04:21:04 +08:00
|
|
|
const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
|
2013-07-18 02:25:36 +08:00
|
|
|
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-12-02 04:21:04 +08:00
|
|
|
typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
|
2015-12-18 08:36:55 +08:00
|
|
|
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2021-02-11 05:19:50 +08:00
|
|
|
// [tuple.cnstr]
|
|
|
|
|
|
|
|
// tuple() constructors (including allocator_arg_t variants)
|
2021-09-08 21:14:43 +08:00
|
|
|
template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_IsImpDefault<_Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2021-05-01 03:52:26 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2019-09-26 22:51:10 +08:00
|
|
|
tuple()
|
2021-02-11 05:19:50 +08:00
|
|
|
_NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_IsDefault<_Tp>...,
|
|
|
|
_Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
|
|
|
explicit tuple()
|
|
|
|
_NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_IsImpDefault<_Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2021-02-11 05:19:50 +08:00
|
|
|
tuple(allocator_arg_t, _Alloc const& __a)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __base_(allocator_arg_t(), __a,
|
2016-04-15 11:29:40 +08:00
|
|
|
__tuple_indices<>(), __tuple_types<>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
|
|
|
|
__tuple_types<_Tp...>()) {}
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
template <class _Alloc,
|
|
|
|
template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_IsDefault<_Tp>...,
|
|
|
|
_Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, _Alloc const& __a)
|
2019-09-27 23:06:52 +08:00
|
|
|
: __base_(allocator_arg_t(), __a,
|
|
|
|
__tuple_indices<>(), __tuple_types<>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
|
|
|
|
__tuple_types<_Tp...>()) {}
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
// tuple(const T&...) constructors (including allocator_arg_t variants)
|
2021-09-08 21:14:43 +08:00
|
|
|
template <template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) >= 1>,
|
|
|
|
is_copy_constructible<_Tp>...,
|
|
|
|
is_convertible<const _Tp&, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2021-02-11 05:19:50 +08:00
|
|
|
tuple(const _Tp& ... __t)
|
|
|
|
_NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_indices<0>::type(),
|
|
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
|
|
__t...
|
|
|
|
) {}
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) >= 1>,
|
|
|
|
is_copy_constructible<_Tp>...,
|
|
|
|
_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2016-04-19 09:19:25 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2021-02-11 05:19:50 +08:00
|
|
|
explicit tuple(const _Tp& ... __t)
|
|
|
|
_NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
2016-04-19 09:19:25 +08:00
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_indices<0>::type(),
|
|
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
|
|
__t...
|
|
|
|
) {}
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) >= 1>,
|
|
|
|
is_copy_constructible<_Tp>...,
|
|
|
|
is_convertible<const _Tp&, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __base_(allocator_arg_t(), __a,
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_indices<0>::type(),
|
|
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
|
|
__t...
|
|
|
|
) {}
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) >= 1>,
|
|
|
|
is_copy_constructible<_Tp>...,
|
|
|
|
_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
|
2017-06-01 10:14:21 +08:00
|
|
|
: __base_(allocator_arg_t(), __a,
|
2016-04-19 09:19:25 +08:00
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
|
|
typename __make_tuple_indices<0>::type(),
|
|
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
|
|
__t...
|
|
|
|
) {}
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
// tuple(U&& ...) constructors (including allocator_arg_t variants)
|
|
|
|
template <class ..._Up> struct _IsThisTuple : false_type { };
|
|
|
|
template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
|
|
|
|
|
|
|
|
template <class ..._Up>
|
|
|
|
struct _EnableUTypesCtor : _And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) >= 1>,
|
|
|
|
_Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
|
|
|
|
is_constructible<_Tp, _Up>...
|
|
|
|
> { };
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
|
|
|
|
_EnableUTypesCtor<_Up...>,
|
|
|
|
is_convertible<_Up, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
tuple(_Up&&... __u)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
|
|
|
|
: __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
2012-04-02 07:10:42 +08:00
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
_VSTD::forward<_Up>(__u)...) {}
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
|
|
|
|
_EnableUTypesCtor<_Up...>,
|
|
|
|
_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
explicit tuple(_Up&&... __u)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
|
|
|
|
: __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Up>(__u)...) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
|
|
|
|
_EnableUTypesCtor<_Up...>,
|
|
|
|
is_convertible<_Up, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
|
|
|
|
: __base_(allocator_arg_t(), __a,
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Up>(__u)...) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
|
|
|
|
_EnableUTypesCtor<_Up...>,
|
|
|
|
_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
|
|
|
|
: __base_(allocator_arg_t(), __a,
|
2016-04-19 09:19:25 +08:00
|
|
|
typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
|
|
_VSTD::forward<_Up>(__u)...) {}
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
// Copy and move constructors (including the allocator_arg_t variants)
|
|
|
|
tuple(const tuple&) = default;
|
|
|
|
tuple(tuple&&) = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<is_copy_constructible<_Tp>...>::value
|
|
|
|
, int> = 0>
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2021-02-11 05:19:50 +08:00
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
|
|
|
|
: __base_(allocator_arg_t(), __alloc, __t)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<is_move_constructible<_Tp>...>::value
|
|
|
|
, int> = 0>
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2021-02-11 05:19:50 +08:00
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
|
|
|
|
: __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
|
2022-06-27 21:36:52 +08:00
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template <class _OtherTuple, class _DecayedOtherTuple = __uncvref_t<_OtherTuple>, class = void>
|
|
|
|
struct _EnableCtorFromUTypesTuple : false_type {};
|
|
|
|
|
|
|
|
template <class _OtherTuple, class... _Up>
|
2022-06-27 21:36:52 +08:00
|
|
|
struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
// the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
|
|
|
|
__enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
|
|
|
|
// the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
|
|
|
|
// Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
|
|
|
|
_Not<is_same<_OtherTuple, const tuple&> >,
|
|
|
|
_Not<is_same<_OtherTuple, tuple&&> >,
|
|
|
|
is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
|
|
|
|
_Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
|
2021-02-11 05:19:50 +08:00
|
|
|
// _Tp and _Up are 1-element packs - the pack expansions look
|
|
|
|
// weird to avoid tripping up the type traits in degenerate cases
|
|
|
|
_Lazy<_And,
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_Not<is_same<_Tp, _Up> >...,
|
|
|
|
_Not<is_convertible<_OtherTuple, _Tp> >...,
|
|
|
|
_Not<is_constructible<_Tp, _OtherTuple> >...
|
2021-02-11 05:19:50 +08:00
|
|
|
>
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
>
|
|
|
|
> {};
|
2021-02-11 05:19:50 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
is_convertible<const _Up&, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
tuple(const tuple<_Up...>& __t)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
|
|
|
|
: __base_(__t)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
explicit tuple(const tuple<_Up...>& __t)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
|
|
|
|
: __base_(__t)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, class _Alloc, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
is_convertible<const _Up&, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
|
|
|
|
: __base_(allocator_arg_t(), __a, __t)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, class _Alloc, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
|
|
|
|
: __base_(allocator_arg_t(), __a, __t)
|
|
|
|
{ }
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
// tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
|
|
|
|
|
|
|
|
template <class... _Up, enable_if_t<
|
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!(is_convertible_v<_Up&, _Tp> && ...))
|
|
|
|
tuple(tuple<_Up...>& __t) : __base_(__t) {}
|
|
|
|
|
|
|
|
template <class _Alloc, class... _Up, enable_if_t<
|
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!(is_convertible_v<_Up&, _Tp> && ...))
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
// tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
is_convertible<_Up, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
tuple(tuple<_Up...>&& __t)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
|
|
|
|
: __base_(_VSTD::move(__t))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
explicit tuple(tuple<_Up...>&& __t)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
|
|
|
|
: __base_(_VSTD::move(__t))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
is_convertible<_Up, _Tp>... // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
|
|
|
|
: __base_(allocator_arg_t(), __a, _VSTD::move(__t))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class ..._Up, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
|
2021-02-11 05:19:50 +08:00
|
|
|
_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
|
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
|
|
|
|
: __base_(allocator_arg_t(), __a, _VSTD::move(__t))
|
|
|
|
{ }
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
// tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
|
|
|
|
|
|
|
|
template <class... _Up, enable_if_t<
|
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
|
|
|
|
tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
|
|
|
|
|
|
|
|
template <class _Alloc, class... _Up, enable_if_t<
|
|
|
|
_EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
|
|
|
|
: __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
2021-02-11 05:19:50 +08:00
|
|
|
// tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template <template <class...> class Pred, class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
|
|
|
|
struct _CtorPredicateFromPair : false_type{};
|
|
|
|
|
|
|
|
template <template <class...> class Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
|
|
|
|
struct _CtorPredicateFromPair<Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
|
|
|
|
Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
|
|
|
|
Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
|
|
|
|
> {};
|
|
|
|
|
|
|
|
template <class _Pair>
|
|
|
|
struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
|
|
|
|
|
|
|
|
template <class _Pair>
|
|
|
|
struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
|
|
|
|
|
|
|
|
template <class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
|
|
|
|
struct _BothImplicitlyConvertible : false_type{};
|
|
|
|
|
|
|
|
template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
|
|
|
|
struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
|
|
|
|
is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
|
|
|
|
is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
|
|
|
|
> {};
|
2021-02-11 05:19:50 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<const pair<_Up1, _Up2>&>,
|
|
|
|
_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
tuple(const pair<_Up1, _Up2>& __p)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
|
2021-02-11 05:19:50 +08:00
|
|
|
: __base_(__p)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<const pair<_Up1, _Up2>&>,
|
|
|
|
_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
explicit tuple(const pair<_Up1, _Up2>& __p)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
|
2021-02-11 05:19:50 +08:00
|
|
|
: __base_(__p)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<const pair<_Up1, _Up2>&>,
|
|
|
|
_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
|
|
|
|
: __base_(allocator_arg_t(), __a, __p)
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<const pair<_Up1, _Up2>&>,
|
|
|
|
_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
|
|
|
|
: __base_(allocator_arg_t(), __a, __p)
|
|
|
|
{ }
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
// tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
|
|
|
|
|
|
|
|
template <class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
|
|
|
|
tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
|
|
|
|
|
|
|
|
template <class _Alloc, class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
|
|
|
|
#endif
|
2022-06-24 04:54:23 +08:00
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
// tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
|
2021-02-11 05:19:50 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<pair<_Up1, _Up2>&&>,
|
|
|
|
_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2021-05-01 03:52:26 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2021-02-11 05:19:50 +08:00
|
|
|
tuple(pair<_Up1, _Up2>&& __p)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
|
2021-02-11 05:19:50 +08:00
|
|
|
: __base_(_VSTD::move(__p))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<pair<_Up1, _Up2>&&>,
|
|
|
|
_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
2021-05-01 03:52:26 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2021-02-11 05:19:50 +08:00
|
|
|
explicit tuple(pair<_Up1, _Up2>&& __p)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
|
2021-02-11 05:19:50 +08:00
|
|
|
: __base_(_VSTD::move(__p))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<pair<_Up1, _Up2>&&>,
|
|
|
|
_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
|
|
|
|
: __base_(allocator_arg_t(), __a, _VSTD::move(__p))
|
|
|
|
{ }
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
|
2021-02-11 05:19:50 +08:00
|
|
|
_And<
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_EnableCtorFromPair<pair<_Up1, _Up2>&&>,
|
|
|
|
_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
|
2021-02-11 05:19:50 +08:00
|
|
|
>::value
|
|
|
|
, int> = 0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
|
|
|
|
: __base_(allocator_arg_t(), __a, _VSTD::move(__p))
|
|
|
|
{ }
|
2016-04-19 09:19:25 +08:00
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
// tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
|
|
|
|
|
|
|
|
template <class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
|
|
|
|
tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
|
|
|
|
|
|
|
|
template <class _Alloc, class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
|
|
|
|
tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
|
|
|
|
: __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
2018-07-31 23:56:20 +08:00
|
|
|
// [tuple.assign]
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
|
|
|
|
{
|
|
|
|
_VSTD::__memberwise_copy_assign(*this, __tuple,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(tuple const& __tuple) const
|
|
|
|
requires (_And<is_copy_assignable<const _Tp>...>::value) {
|
|
|
|
std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(tuple&& __tuple) const
|
|
|
|
requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
|
|
|
|
std::__memberwise_forward_assign(*this,
|
|
|
|
std::move(__tuple),
|
|
|
|
__tuple_types<_Tp...>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
|
|
|
|
{
|
|
|
|
_VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
|
|
|
|
__tuple_types<_Tp...>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
2016-07-25 10:36:42 +08:00
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class... _Up, __enable_if_t<
|
2018-07-31 23:56:20 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
|
|
|
|
is_assignable<_Tp&, _Up const&>...
|
|
|
|
>::value
|
|
|
|
,int> = 0>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(tuple<_Up...> const& __tuple)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
|
2016-07-25 10:36:42 +08:00
|
|
|
{
|
2018-07-31 23:56:20 +08:00
|
|
|
_VSTD::__memberwise_copy_assign(*this, __tuple,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
2016-07-25 10:36:42 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class... _Up, __enable_if_t<
|
2018-07-31 23:56:20 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
|
|
|
|
is_assignable<_Tp&, _Up>...
|
|
|
|
>::value
|
|
|
|
,int> = 0>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(tuple<_Up...>&& __tuple)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
|
2016-07-25 10:36:42 +08:00
|
|
|
{
|
2018-07-31 23:56:20 +08:00
|
|
|
_VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
|
|
|
|
__tuple_types<_Up...>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
2016-07-25 10:36:42 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
template <class... _UTypes, enable_if_t<
|
|
|
|
_And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
|
|
|
|
is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(const tuple<_UTypes...>& __u) const {
|
|
|
|
std::__memberwise_copy_assign(*this,
|
|
|
|
__u,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... _UTypes, enable_if_t<
|
|
|
|
_And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
|
|
|
|
is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(tuple<_UTypes...>&& __u) const {
|
|
|
|
std::__memberwise_forward_assign(*this,
|
|
|
|
__u,
|
|
|
|
__tuple_types<_UTypes...>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
2022-06-27 21:36:52 +08:00
|
|
|
template <template<class...> class Pred, bool _Const,
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
|
|
|
|
struct _AssignPredicateFromPair : false_type {};
|
|
|
|
|
2022-06-27 21:36:52 +08:00
|
|
|
template <template<class...> class Pred, bool _Const,
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
|
2022-06-27 21:36:52 +08:00
|
|
|
struct _AssignPredicateFromPair<Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_And<Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
|
|
|
|
Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
|
|
|
|
> {};
|
|
|
|
|
|
|
|
template <bool _Const, class _Pair>
|
|
|
|
struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
|
|
|
|
|
|
|
|
template <bool _Const, class _Pair>
|
|
|
|
struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
template <class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(const pair<_U1, _U2>& __pair) const
|
|
|
|
noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
|
|
|
|
std::get<0>(*this) = __pair.first;
|
|
|
|
std::get<1>(*this) = __pair.second;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _U1, class _U2, enable_if_t<
|
|
|
|
_EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
const tuple& operator=(pair<_U1, _U2>&& __pair) const
|
|
|
|
noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
|
|
|
|
std::get<0>(*this) = std::move(__pair.first);
|
|
|
|
std::get<1>(*this) = std::move(__pair.second);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
|
|
|
|
|
|
|
template<class _Up1, class _Up2, __enable_if_t<
|
|
|
|
_EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
|
2018-07-31 23:56:20 +08:00
|
|
|
,int> = 0>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(pair<_Up1, _Up2> const& __pair)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
|
2018-07-31 23:56:20 +08:00
|
|
|
{
|
|
|
|
_VSTD::get<0>(*this) = __pair.first;
|
|
|
|
_VSTD::get<1>(*this) = __pair.second;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
template<class _Up1, class _Up2, __enable_if_t<
|
|
|
|
_EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
|
2018-07-31 23:56:20 +08:00
|
|
|
,int> = 0>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(pair<_Up1, _Up2>&& __pair)
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
_NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
|
2018-07-31 23:56:20 +08:00
|
|
|
{
|
2021-02-25 03:53:21 +08:00
|
|
|
_VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
|
|
|
|
_VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
|
2018-07-31 23:56:20 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXTENSION
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class _Up, size_t _Np, class = __enable_if_t<
|
2018-07-31 23:56:20 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<_Np == sizeof...(_Tp)>,
|
|
|
|
is_assignable<_Tp&, _Up const&>...
|
|
|
|
>::value
|
|
|
|
> >
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(array<_Up, _Np> const& __array)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
|
|
|
|
{
|
|
|
|
_VSTD::__memberwise_copy_assign(*this, __array,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXTENSION
|
2021-09-08 21:14:43 +08:00
|
|
|
template<class _Up, size_t _Np, class = void, class = __enable_if_t<
|
2018-07-31 23:56:20 +08:00
|
|
|
_And<
|
|
|
|
_BoolConstant<_Np == sizeof...(_Tp)>,
|
|
|
|
is_assignable<_Tp&, _Up>...
|
|
|
|
>::value
|
|
|
|
> >
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-07-31 23:56:20 +08:00
|
|
|
tuple& operator=(array<_Up, _Np>&& __array)
|
|
|
|
_NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
|
|
|
|
{
|
|
|
|
_VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
|
|
|
|
__tuple_types<_If<true, _Up, _Tp>...>(),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type());
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-07-31 23:56:20 +08:00
|
|
|
// [tuple.swap]
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2011-05-28 03:08:18 +08:00
|
|
|
void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
|
2017-06-01 10:14:21 +08:00
|
|
|
{__base_.swap(__t.__base_);}
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
|
|
|
|
__base_.swap(__t.__base_);
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS tuple<>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
|
|
|
tuple() _NOEXCEPT = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2012-07-07 05:53:48 +08:00
|
|
|
tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Alloc>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2012-07-07 05:53:48 +08:00
|
|
|
tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Up>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2012-07-07 05:53:48 +08:00
|
|
|
tuple(array<_Up, 0>) _NOEXCEPT {}
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Alloc, class _Up>
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2012-07-07 05:53:48 +08:00
|
|
|
tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
|
2021-02-10 08:12:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2011-05-28 03:08:18 +08:00
|
|
|
void swap(tuple&) _NOEXCEPT {}
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2022-03-12 23:46:57 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
2022-01-18 02:45:42 +08:00
|
|
|
template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
|
|
|
|
requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
|
|
|
|
struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
|
|
|
|
using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class... _TTypes, class... _UTypes>
|
|
|
|
requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
|
|
|
|
struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
|
|
|
|
using type = tuple<common_type_t<_TTypes, _UTypes>...>;
|
|
|
|
};
|
2022-03-12 23:46:57 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 20
|
2022-01-18 02:45:42 +08:00
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 14
|
2019-08-13 02:30:31 +08:00
|
|
|
template <class ..._Tp>
|
|
|
|
tuple(_Tp...) -> tuple<_Tp...>;
|
|
|
|
template <class _Tp1, class _Tp2>
|
|
|
|
tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
|
|
|
|
template <class _Alloc, class ..._Tp>
|
|
|
|
tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
|
|
|
|
template <class _Alloc, class _Tp1, class _Tp2>
|
|
|
|
tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
|
|
|
|
template <class _Alloc, class ..._Tp>
|
|
|
|
tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
|
2017-06-08 15:18:17 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ..._Tp>
|
2021-02-10 08:12:16 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2022-07-04 07:21:44 +08:00
|
|
|
__enable_if_t<__all<__is_swappable<_Tp>::value...>::value, void>
|
2011-05-28 03:08:18 +08:00
|
|
|
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
|
|
|
|
_NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
|
|
|
|
{__t.swap(__u);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
[libc++] P2321R2 section [tuple.tuple]. Adding C++23 constructors, assignment operators and swaps to `tuple`
1. for constructors that takes cvref variation of tuple<UTypes...>, there
used to be two SFINAE helper _EnableCopyFromOtherTuple,
_EnableMoveFromOtherTuple. And the implementations of these two helpers
seem to slightly differ from the spec. But now, we need 4 variations.
Instead of adding another two, this change refactored it to a single one
_EnableCtrFromUTypesTuple, which directly maps to the spec without
changing the C++11 behaviour. However, we need the helper __copy_cvref_t
to get the type of std::get<i>(cvref tuple<Utypes...>) for different
cvref, so I made __copy_cvref_t to be available in C++11.
2. for constructors that takes variations of std::pair, there used to be
four helpers _EnableExplicitCopyFromPair, _EnableImplicitCopyFromPair,
_EnableImplicitMoveFromPair, _EnableExplicitMoveFromPair. Instead of
adding another four, this change refactored into two helper
_EnableCtrFromPair and _BothImplicitlyConvertible. This also removes the
need to use _nat
3. for const member assignment operator, since the requirement is very
simple, I haven't refactored the old code but instead directly adding
the new c++23 code.
4. for const swap, I pretty much copy pasted the non-const version to make
these overloads look consistent
5. while doing these change, I found two of the old constructors wasn't
marked constexpr for C++20 but they should. fixed them and added unit
tests
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D116621
2022-05-12 20:23:11 +08:00
|
|
|
#if _LIBCPP_STD_VER > 20
|
|
|
|
template <class... _Tp>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
|
|
|
|
swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
|
|
|
|
noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
|
|
|
|
__lhs.swap(__rhs);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// get
|
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
typename tuple_element<_Ip, tuple<_Tp...> >::type&
|
2011-12-02 04:21:04 +08:00
|
|
|
get(tuple<_Tp...>& __t) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
|
2017-06-01 10:14:21 +08:00
|
|
|
return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
const typename tuple_element<_Ip, tuple<_Tp...> >::type&
|
2011-12-02 04:21:04 +08:00
|
|
|
get(const tuple<_Tp...>& __t) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
|
2017-06-01 10:14:21 +08:00
|
|
|
return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-11-18 03:52:17 +08:00
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
typename tuple_element<_Ip, tuple<_Tp...> >::type&&
|
2011-12-02 04:21:04 +08:00
|
|
|
get(tuple<_Tp...>&& __t) _NOEXCEPT
|
2010-11-18 03:52:17 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
|
2011-01-26 00:31:30 +08:00
|
|
|
return static_cast<type&&>(
|
2017-06-01 10:14:21 +08:00
|
|
|
static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
|
2010-11-18 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
2015-12-18 08:36:55 +08:00
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
|
|
|
|
get(const tuple<_Tp...>&& __t) _NOEXCEPT
|
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
|
2015-12-18 08:36:55 +08:00
|
|
|
return static_cast<const type&&>(
|
2017-06-01 10:14:21 +08:00
|
|
|
static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
|
2015-12-18 08:36:55 +08:00
|
|
|
}
|
|
|
|
|
2013-07-13 10:54:05 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
|
2016-07-02 11:18:30 +08:00
|
|
|
namespace __find_detail {
|
2013-07-13 10:54:05 +08:00
|
|
|
|
2021-07-20 23:46:05 +08:00
|
|
|
static constexpr size_t __not_found = static_cast<size_t>(-1);
|
2016-07-02 11:18:30 +08:00
|
|
|
static constexpr size_t __ambiguous = __not_found - 1;
|
2013-07-13 10:54:05 +08:00
|
|
|
|
2016-07-02 11:18:30 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
|
|
|
|
return !__matches ? __res :
|
|
|
|
(__res == __not_found ? __curr_i : __ambiguous);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Nx>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
|
|
|
|
return __i == _Nx ? __not_found :
|
|
|
|
__find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class ..._Args>
|
|
|
|
struct __find_exactly_one_checked {
|
2017-12-13 01:22:24 +08:00
|
|
|
static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
|
2016-07-02 11:18:30 +08:00
|
|
|
static constexpr size_t value = __find_detail::__find_idx(0, __matches);
|
2017-12-13 01:22:24 +08:00
|
|
|
static_assert(value != __not_found, "type not found in type list" );
|
|
|
|
static_assert(value != __ambiguous, "type occurs more than once in type list");
|
2016-07-02 11:18:30 +08:00
|
|
|
};
|
|
|
|
|
2016-07-02 11:46:08 +08:00
|
|
|
template <class _T1>
|
|
|
|
struct __find_exactly_one_checked<_T1> {
|
|
|
|
static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
|
|
|
|
};
|
|
|
|
|
2021-12-02 21:12:51 +08:00
|
|
|
} // namespace __find_detail
|
2013-07-13 10:54:05 +08:00
|
|
|
|
|
|
|
template <typename _T1, typename... _Args>
|
2016-07-02 11:18:30 +08:00
|
|
|
struct __find_exactly_one_t
|
|
|
|
: public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
|
|
|
|
};
|
2013-07-13 10:54:05 +08:00
|
|
|
|
|
|
|
template <class _T1, class... _Args>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _T1& get(tuple<_Args...>& __tup) noexcept
|
|
|
|
{
|
|
|
|
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class... _Args>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
|
|
|
|
{
|
|
|
|
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class... _Args>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
|
|
|
|
{
|
2013-07-16 04:46:11 +08:00
|
|
|
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
|
2013-07-13 10:54:05 +08:00
|
|
|
}
|
|
|
|
|
2015-12-18 08:36:55 +08:00
|
|
|
template <class _T1, class... _Args>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
|
|
|
|
{
|
|
|
|
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
|
|
|
|
}
|
|
|
|
|
2013-07-13 10:54:05 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// tie
|
|
|
|
|
|
|
|
template <class ..._Tp>
|
2014-02-26 00:11:46 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
tuple<_Tp&...>
|
2012-07-07 05:53:48 +08:00
|
|
|
tie(_Tp&... __t) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return tuple<_Tp&...>(__t...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Up>
|
|
|
|
struct __ignore_t
|
|
|
|
{
|
|
|
|
template <class _Tp>
|
2017-02-06 09:25:31 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const __ignore_t& operator=(_Tp&&) const {return *this;}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-02-06 09:25:31 +08:00
|
|
|
namespace {
|
2021-09-22 21:35:32 +08:00
|
|
|
constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
|
2021-12-02 21:12:51 +08:00
|
|
|
} // namespace
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class... _Tp>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2018-12-03 22:03:27 +08:00
|
|
|
tuple<typename __unwrap_ref_decay<_Tp>::type...>
|
2010-05-12 03:42:16 +08:00
|
|
|
make_tuple(_Tp&&... __t)
|
|
|
|
{
|
2018-12-03 22:03:27 +08:00
|
|
|
return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
|
2010-08-20 02:59:38 +08:00
|
|
|
}
|
|
|
|
|
2013-07-23 00:02:19 +08:00
|
|
|
template <class... _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
tuple<_Tp&&...>
|
2012-07-07 05:53:48 +08:00
|
|
|
forward_as_tuple(_Tp&&... __t) _NOEXCEPT
|
2010-08-20 02:59:38 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <size_t _Ip>
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __tuple_equal
|
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator()(const _Tp& __x, const _Up& __y)
|
|
|
|
{
|
2014-06-24 08:46:19 +08:00
|
|
|
return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct __tuple_equal<0>
|
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator()(const _Tp&, const _Up&)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
2019-02-08 03:03:48 +08:00
|
|
|
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
|
2010-05-12 03:42:16 +08:00
|
|
|
return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
|
|
|
|
}
|
|
|
|
|
2022-03-12 23:46:57 +08:00
|
|
|
#if _LIBCPP_STD_VER > 17
|
2021-10-09 05:54:28 +08:00
|
|
|
|
|
|
|
// operator<=>
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up, size_t ..._Is>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
auto
|
|
|
|
__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
|
|
|
|
common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
|
|
|
|
static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
|
|
|
|
return __result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
|
|
requires (sizeof...(_Tp) == sizeof...(_Up))
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr
|
|
|
|
common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
|
|
|
|
operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
|
|
|
return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
|
|
|
|
}
|
|
|
|
|
2022-03-12 23:46:57 +08:00
|
|
|
#else // _LIBCPP_STD_VER > 17
|
2021-10-09 05:54:28 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <size_t _Ip>
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __tuple_less
|
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator()(const _Tp& __x, const _Up& __y)
|
|
|
|
{
|
2015-01-21 10:51:17 +08:00
|
|
|
const size_t __idx = tuple_size<_Tp>::value - _Ip;
|
|
|
|
if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
|
|
|
|
return true;
|
|
|
|
if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
|
|
|
|
return false;
|
|
|
|
return __tuple_less<_Ip-1>()(__x, __y);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct __tuple_less<0>
|
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator()(const _Tp&, const _Up&)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
2019-02-08 03:03:48 +08:00
|
|
|
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
|
2010-05-12 03:42:16 +08:00
|
|
|
return __tuple_less<sizeof...(_Tp)>()(__x, __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Tp, class ..._Up>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
bool
|
|
|
|
operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
2022-03-12 23:46:57 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 17
|
2021-10-09 05:54:28 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// tuple_cat
|
|
|
|
|
2010-12-12 04:47:50 +08:00
|
|
|
template <class _Tp, class _Up> struct __tuple_cat_type;
|
|
|
|
|
|
|
|
template <class ..._Ttypes, class ..._Utypes>
|
2011-01-25 00:07:25 +08:00
|
|
|
struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
|
2010-12-12 04:47:50 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-12-12 04:47:50 +08:00
|
|
|
template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
|
|
|
|
struct __tuple_cat_return_1
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-12-12 04:47:50 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-12-12 04:47:50 +08:00
|
|
|
template <class ..._Types, class _Tuple0>
|
|
|
|
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2022-02-18 05:53:20 +08:00
|
|
|
using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
|
|
|
|
tuple<_Types...>,
|
|
|
|
typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
|
|
|
|
>::type;
|
2010-12-12 04:47:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
|
|
|
|
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
|
|
|
|
: public __tuple_cat_return_1<
|
|
|
|
typename __tuple_cat_type<
|
|
|
|
tuple<_Types...>,
|
2022-02-18 05:53:20 +08:00
|
|
|
typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
|
2010-12-12 04:47:50 +08:00
|
|
|
>::type,
|
|
|
|
__tuple_like<typename remove_reference<_Tuple1>::type>::value,
|
|
|
|
_Tuple1, _Tuples...>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Tuples> struct __tuple_cat_return;
|
|
|
|
|
|
|
|
template <class _Tuple0, class ..._Tuples>
|
|
|
|
struct __tuple_cat_return<_Tuple0, _Tuples...>
|
|
|
|
: public __tuple_cat_return_1<tuple<>,
|
|
|
|
__tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
|
|
|
|
_Tuples...>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct __tuple_cat_return<>
|
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG tuple<> type;
|
2010-12-12 04:47:50 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-12-12 04:47:50 +08:00
|
|
|
tuple<>
|
|
|
|
tuple_cat()
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-12-12 04:47:50 +08:00
|
|
|
return tuple<>();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
|
2010-12-13 07:04:37 +08:00
|
|
|
struct __tuple_cat_return_ref_imp;
|
|
|
|
|
|
|
|
template <class ..._Types, size_t ..._I0, class _Tuple0>
|
|
|
|
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
|
2010-12-13 07:04:37 +08:00
|
|
|
typedef tuple<_Types..., typename __apply_cv<_Tuple0,
|
|
|
|
typename tuple_element<_I0, _T0>::type>::type&&...> type;
|
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-12-13 07:04:37 +08:00
|
|
|
template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
|
|
|
|
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
|
|
|
|
_Tuple0, _Tuple1, _Tuples...>
|
|
|
|
: public __tuple_cat_return_ref_imp<
|
|
|
|
tuple<_Types..., typename __apply_cv<_Tuple0,
|
|
|
|
typename tuple_element<_I0,
|
|
|
|
typename remove_reference<_Tuple0>::type>::type>::type&&...>,
|
|
|
|
typename __make_tuple_indices<tuple_size<typename
|
|
|
|
remove_reference<_Tuple1>::type>::value>::type,
|
|
|
|
_Tuple1, _Tuples...>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-12-13 07:04:37 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-12-13 07:04:37 +08:00
|
|
|
template <class _Tuple0, class ..._Tuples>
|
|
|
|
struct __tuple_cat_return_ref
|
|
|
|
: public __tuple_cat_return_ref_imp<tuple<>,
|
|
|
|
typename __make_tuple_indices<
|
|
|
|
tuple_size<typename remove_reference<_Tuple0>::type>::value
|
|
|
|
>::type, _Tuple0, _Tuples...>
|
2010-12-12 04:47:50 +08:00
|
|
|
{
|
2010-12-13 07:04:37 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-12-13 07:04:37 +08:00
|
|
|
template <class _Types, class _I0, class _J0>
|
|
|
|
struct __tuple_cat;
|
|
|
|
|
|
|
|
template <class ..._Types, size_t ..._I0, size_t ..._J0>
|
2011-01-25 00:07:25 +08:00
|
|
|
struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
|
2010-12-13 07:04:37 +08:00
|
|
|
{
|
|
|
|
template <class _Tuple0>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-12-13 07:04:37 +08:00
|
|
|
typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
|
|
|
|
operator()(tuple<_Types...> __t, _Tuple0&& __t0)
|
|
|
|
{
|
2022-03-04 02:39:12 +08:00
|
|
|
(void)__t; // avoid unused parameter warning on GCC when _I0 is empty
|
2019-10-29 09:03:59 +08:00
|
|
|
return _VSTD::forward_as_tuple(
|
|
|
|
_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
|
|
|
|
_VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
|
2010-12-13 07:04:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tuple0, class _Tuple1, class ..._Tuples>
|
2013-07-23 00:02:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-12-13 07:04:37 +08:00
|
|
|
typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
|
|
|
|
operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
|
|
|
|
{
|
2022-03-04 02:39:12 +08:00
|
|
|
(void)__t; // avoid unused parameter warning on GCC when _I0 is empty
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
|
|
|
|
typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
|
2010-12-13 07:04:37 +08:00
|
|
|
return __tuple_cat<
|
2019-10-29 09:03:59 +08:00
|
|
|
tuple<_Types...,
|
|
|
|
typename __apply_cv<_Tuple0, typename tuple_element<
|
|
|
|
_J0, _T0>::type>::type&&...>,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Types) +
|
|
|
|
tuple_size<_T0>::value>::type,
|
|
|
|
typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
|
|
|
|
_VSTD::forward_as_tuple(
|
|
|
|
_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
|
|
|
|
_VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
|
|
|
|
_VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
|
2010-12-13 07:04:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tuple0, class... _Tuples>
|
2013-07-23 00:02:19 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-12-13 07:04:37 +08:00
|
|
|
typename __tuple_cat_return<_Tuple0, _Tuples...>::type
|
|
|
|
tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
|
2010-12-13 07:04:37 +08:00
|
|
|
return __tuple_cat<tuple<>, __tuple_indices<>,
|
|
|
|
typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
|
2011-07-01 05:18:19 +08:00
|
|
|
(tuple<>(), _VSTD::forward<_Tuple0>(__t0),
|
|
|
|
_VSTD::forward<_Tuples>(__tpls)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Tp, class _Alloc>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
|
2010-05-12 03:42:16 +08:00
|
|
|
: true_type {};
|
|
|
|
|
|
|
|
template <class _T1, class _T2>
|
|
|
|
template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
|
2020-09-03 03:20:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2010-05-12 03:42:16 +08:00
|
|
|
pair<_T1, _T2>::pair(piecewise_construct_t,
|
|
|
|
tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
|
|
|
|
__tuple_indices<_I1...>, __tuple_indices<_I2...>)
|
2014-06-24 08:46:19 +08:00
|
|
|
: first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
|
|
|
|
second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-18 08:35:56 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <class _Tp>
|
2021-09-22 21:35:32 +08:00
|
|
|
inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
|
2016-07-18 08:35:56 +08:00
|
|
|
|
|
|
|
#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
|
|
|
|
|
|
|
|
template <class _Fn, class _Tuple, size_t ..._Id>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
|
|
|
|
__tuple_indices<_Id...>)
|
|
|
|
_LIBCPP_NOEXCEPT_RETURN(
|
2022-04-07 05:10:21 +08:00
|
|
|
_VSTD::__invoke(
|
2016-07-18 08:35:56 +08:00
|
|
|
_VSTD::forward<_Fn>(__f),
|
|
|
|
_VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
|
|
|
|
)
|
|
|
|
|
|
|
|
template <class _Fn, class _Tuple>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
|
|
|
|
_LIBCPP_NOEXCEPT_RETURN(
|
|
|
|
_VSTD::__apply_tuple_impl(
|
|
|
|
_VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
|
2018-02-07 04:56:55 +08:00
|
|
|
typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
|
2016-07-18 08:35:56 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
template <class _Tp, class _Tuple, size_t... _Idx>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
|
|
|
|
_LIBCPP_NOEXCEPT_RETURN(
|
|
|
|
_Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
|
|
|
|
)
|
|
|
|
|
|
|
|
template <class _Tp, class _Tuple>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr _Tp make_from_tuple(_Tuple&& __t)
|
|
|
|
_LIBCPP_NOEXCEPT_RETURN(
|
|
|
|
_VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
|
2018-02-07 04:56:55 +08:00
|
|
|
typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
|
2016-07-18 08:35:56 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
#undef _LIBCPP_NOEXCEPT_RETURN
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER > 14
|
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#endif // !defined(_LIBCPP_CXX03_LANG)
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_TUPLE
|