Logo ROOT   6.14/05
Reference Guide
impl_tuple_apply.hxx
Go to the documentation of this file.
1 /// \file ROOT/impl_tuple_apply.h
2 /// \ingroup Base StdExt ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-09
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_Impl_Tuple_Apply
16 #define ROOT7_Impl_Tuple_Apply
17 
18 #include "RConfigure.h"
19 
20 #include <functional>
21 
22 // std::experimental::apply, invoke until it's there...
23 // from http://en.cppreference.com/w/cpp/utility/functional/invoke
24 
25 #ifndef R__HAS_STD_INVOKE
26 namespace ROOT {
27 namespace Detail {
28 template <class F, class... Args>
29 inline auto INVOKE(F&& f, Args&&... args) ->
30 decltype(std::forward<F>(f)(std::forward<Args>(args)...)) {
31  return std::forward<F>(f)(std::forward<Args>(args)...);
32 }
33 
34 template <class Base, class T, class Derived>
35 inline auto INVOKE(T Base::*pmd, Derived&& ref) ->
36 decltype(std::forward<Derived>(ref).*pmd) {
37  return std::forward<Derived>(ref).*pmd;
38 }
39 
40 template <class PMD, class Pointer>
41 inline auto INVOKE(PMD pmd, Pointer&& ptr) ->
42 decltype((*std::forward<Pointer>(ptr)).*pmd) {
43  return (*std::forward<Pointer>(ptr)).*pmd;
44 }
45 
46 template <class Base, class T, class Derived, class... Args>
47 inline auto INVOKE(T Base::*pmf, Derived&& ref, Args&&... args) ->
48 decltype((std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...)) {
49  return (std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...);
50 }
51 
52 template <class PMF, class Pointer, class... Args>
53 inline auto INVOKE(PMF pmf, Pointer&& ptr, Args&&... args) ->
54 decltype(((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...)) {
55  return ((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...);
56 }
57 } // namespace Detail
58 } // namespace ROOT
59 
60 namespace std {
61 inline namespace __ROOT {
62 
63 template< class F, class... ArgTypes>
64 decltype(auto) invoke(F&& f, ArgTypes&&... args) {
65  return ROOT::Detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...);
66 }
67 
68 } // inline namespace __ROOT {
69 } // namespace std
70 #endif // ndef R__HAS_STD_INVOKE
71 
72 #ifndef R__HAS_STD_APPLY
73 // From http://en.cppreference.com/w/cpp/experimental/apply
74 namespace ROOT {
75 namespace Detail {
76 template<class F, class Tuple, std::size_t... I>
77 constexpr decltype(auto) apply_impl(F &&f, Tuple &&t,
78  std::index_sequence<I...>) {
79  return std::invoke(std::forward<F>(f),
80  std::get<I>(std::forward<Tuple>(t))...);
81  // Note: std::invoke is a C++17 feature
82 }
83 } // namespace Detail
84 } // namespace ROOT
85 
86 namespace std {
87 inline namespace __ROOT {
88 template<class F, class Tuple>
89 constexpr decltype(auto) apply(F &&f, Tuple &&t) {
90  return ROOT::Detail::apply_impl(std::forward<F>(f), std::forward<Tuple>(t),
91  std::make_index_sequence < std::tuple_size <
92  std::decay_t < Tuple >> {} > {});
93 }
94 } // inline namespace __ROOT
95 } // namespace std
96 #endif // ndef R__HAS_STD_APPLY
97 
98 #endif //ROOT7_TUPLE_APPLY_H
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
#define f(i)
Definition: RSha256.hxx:104
STL namespace.
auto INVOKE(F &&f, Args &&... args) -> decltype(std::forward< F >(f)(std::forward< Args >(args)...))
decltype(auto) constexpr apply_impl(F &&f, Tuple &&t, std::index_sequence< I... >)
#define F(x, y, z)
decltype(auto) invoke(F &&f, ArgTypes &&... args)
#define I(x, y, z)
make_integer_sequence< size_t, _Np > make_index_sequence
decltype(auto) constexpr apply(F &&f, Tuple &&t)