cesium-native 0.65.0
Loading...
Searching...
No Matches
transformTuple.h
1#include <cstddef>
2#include <tuple>
3#include <utility>
4
5namespace CesiumUtility {
6
7namespace CesiumImpl {
8
13template <typename Tuple, size_t I>
14using TupleElementReference = decltype(std::get<I>(std::declval<Tuple>()));
15
16} // namespace CesiumImpl
17
29template <typename Tuple, typename Func>
30auto transformTuple(Tuple&& tuple, Func&& f) {
31 constexpr size_t N = std::tuple_size_v<std::remove_reference_t<Tuple>>;
32
33 return [&]<size_t... Is>(std::index_sequence<Is...>) {
34 // Use brace-initialization to guarantee arguments are evaluated in order.
35 // This is not generally guaranteed by "ordinary" function invocation. For
36 // example, func(funcA(), funcB()) could have funcA() _or_ funcB() called
37 // first; the order is unspecified.
38 // Each element is forwarded individually, rather than forwarding the whole
39 // tuple once per element, so that only distinct elements are ever moved.
40 std::tuple result{
41 f(std::forward<CesiumImpl::TupleElementReference<Tuple, Is>>(
42 std::get<Is>(tuple)))...};
43 return result;
44 }
45 (std::make_index_sequence<N>{});
46}
47
48} // namespace CesiumUtility
Utility classes for Cesium.
auto transformTuple(Tuple &&tuple, Func &&f)
Transforms each element of a tuple by applying a function to it.