Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement P2517R1: Conditional noexcept For apply #2959

Merged
merged 5 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions stl/inc/tuple
Original file line number Diff line number Diff line change
Expand Up @@ -874,13 +874,15 @@ _NODISCARD constexpr typename _Tuple_cat1<_Tuples...>::_Ret tuple_cat(_Tuples&&.

#if _HAS_CXX17
template <class _Callable, class _Tuple, size_t... _Indices>
constexpr decltype(auto) _Apply_impl(
_Callable&& _Obj, _Tuple&& _Tpl, index_sequence<_Indices...>) { // invoke _Obj with the elements of _Tpl
constexpr decltype(auto) _Apply_impl(_Callable&& _Obj, _Tuple&& _Tpl, index_sequence<_Indices...>) noexcept(
noexcept(_STD invoke(_STD forward<_Callable>(_Obj), _STD get<_Indices>(_STD forward<_Tuple>(_Tpl))...))) {
return _STD invoke(_STD forward<_Callable>(_Obj), _STD get<_Indices>(_STD forward<_Tuple>(_Tpl))...);
}

template <class _Callable, class _Tuple>
constexpr decltype(auto) apply(_Callable&& _Obj, _Tuple&& _Tpl) { // invoke _Obj with the elements of _Tpl
constexpr decltype(auto) apply(_Callable&& _Obj, _Tuple&& _Tpl) noexcept(
noexcept(_Apply_impl(_STD forward<_Callable>(_Obj), _STD forward<_Tuple>(_Tpl),
make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{}))) {
return _Apply_impl(_STD forward<_Callable>(_Obj), _STD forward<_Tuple>(_Tpl),
make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{});
}
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2517R1_apply_conditional_noexcept/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_17_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <string>
#include <tuple>
#include <type_traits>

using namespace std;

struct NoexceptIf {
template <bool b, class... Ts>
void operator()(std::bool_constant<b>, Ts...) const noexcept(b);
};

constexpr static NoexceptIf noexcept_if;

static_assert(noexcept(apply(noexcept_if, forward_as_tuple(true_type{}))));
static_assert(!noexcept(apply(noexcept_if, forward_as_tuple(false_type{}))));

static_assert(noexcept(apply(noexcept_if, forward_as_tuple(true_type{}, 0))));
static_assert(noexcept(apply(noexcept_if, forward_as_tuple(true_type{}, string{}))));
static_assert(!noexcept(apply(noexcept_if, forward_as_tuple(true_type{}, static_cast<const string&>(string{})))));