1 //===-------- stl_extras.h - Useful STL related functions-------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of the ORC runtime support library. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef ORC_RT_STL_EXTRAS_H 14 #define ORC_RT_STL_EXTRAS_H 15 16 #include <utility> 17 #include <tuple> 18 19 namespace __orc_rt { 20 21 namespace detail { 22 23 template <typename F, typename Tuple, std::size_t... I> 24 decltype(auto) apply_tuple_impl(F &&f, Tuple &&t, std::index_sequence<I...>) { 25 return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...); 26 } 27 28 } // end namespace detail 29 30 /// Given an input tuple (a1, a2, ..., an), pass the arguments of the 31 /// tuple variadically to f as if by calling f(a1, a2, ..., an) and 32 /// return the result. 33 /// 34 /// FIXME: Switch to std::apply once we can use c++17. 35 template <typename F, typename Tuple> 36 decltype(auto) apply_tuple(F &&f, Tuple &&t) { 37 using Indices = std::make_index_sequence< 38 std::tuple_size<typename std::decay<Tuple>::type>::value>; 39 40 return detail::apply_tuple_impl(std::forward<F>(f), std::forward<Tuple>(t), 41 Indices{}); 42 } 43 44 } // namespace __orc_rt 45 46 #endif // ORC_RT_STL_EXTRAS 47