3528. make_from_tuple can perform (the equivalent of) a C-style cast

Section: 22.4.6 [tuple.apply] Status: C++23 Submitter: Tim Song Opened: 2021-02-28 Last modified: 2023-11-22

Priority: 3

View all issues with C++23 status.

Discussion:

make_from_tuple is specified to return T(get<I>(std::forward<Tuple>(t))...). When there is only a single tuple element, this is equivalent to a C-style cast that may be a reinterpret_cast, a const_cast, or an access-bypassing static_cast.

[2021-03-12; Reflector poll]

Set priority to 3 following reflector poll. Set status to Tentatively Ready after five votes in favour during reflector poll.

[2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4878.

  1. Edit 22.4.6 [tuple.apply] as indicated:

    template<class T, class Tuple>
      constexpr T make_from_tuple(Tuple&& t);
    

    […]

    -2- Effects: Given the exposition-only function:

    template<class T, class Tuple, size_t... I>
      requires is_constructible_v<T, decltype(get<I>(declval<Tuple>()))...>
    constexpr T make-from-tuple-impl(Tuple&& t, index_sequence<I...>) {     // exposition only
      return T(get<I>(std::forward<Tuple>(t))...);
    }
    

    Equivalent to:

    return make-from-tuple-impl<T>(
      std::forward<Tuple>(t),
      make_index_sequence<tuple_size_v<remove_reference_t<Tuple>>>{});
    

    [Note 1: The type of T must be supplied as an explicit template parameter, as it cannot be deduced from the argument list. — end note]