Title
make_from_tuple can perform (the equivalent of) a C-style cast
Status
ready
Section
[tuple.apply]
Submitter
Tim Song

Created on 2021-02-28.00:00:00 last changed 1 month ago

Messages

Date: 2021-03-12.15:11:05

Proposed resolution:

This wording is relative to N4878.

  1. Edit [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]

Date: 2021-03-15.00:00:00

[ 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.

Date: 2021-02-28.19:28:08

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.

History
Date User Action Args
2021-03-12 15:11:05adminsetmessages: + msg11737
2021-03-12 15:11:05adminsetstatus: new -> ready
2021-02-28 14:42:33adminsetmessages: + msg11719
2021-02-28 00:00:00admincreate