| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

invoke.h
Go to the documentation of this file.
1 #include <functional>
2 #include <type_traits>
3 #include <utility>
4
5 namespace Gaudi
6 {
7 namespace detail2
8 {
9
10 // An implemention of std::invoke based on
11 // http://en.cppreference.com/w/cpp/utility/functional/invoke
12 template <class T>
13 struct is_reference_wrapper : std::false_type {
14 };
15 template <class U>
16 struct is_reference_wrapper<std::reference_wrapper<U>> : std::true_type {
17 };
18
19 template <class Base, class T, class Derived, class... Args>
20 auto INVOKE( T Base::*pmf, Derived&& ref, Args&&... args ) noexcept(
21 noexcept( ( std::forward<Derived>( ref ).*pmf )( std::forward<Args>( args )... ) ) )
22 -> std::enable_if_t<std::is_function<T>::value && std::is_base_of<Base, std::decay_t<Derived>>::value,
23 decltype( ( std::forward<Derived>( ref ).*pmf )( std::forward<Args>( args )... ) )>
24 {
25 return ( std::forward<Derived>( ref ).*pmf )( std::forward<Args>( args )... );
26 }
27
28 template <class Base, class T, class RefWrap, class... Args>
29 auto INVOKE( T Base::*pmf, RefWrap&& ref,
30 Args&&... args ) noexcept( noexcept( ( ref.get().*pmf )( std::forward<Args>( args )... ) ) )
31 -> std::enable_if_t<std::is_function<T>::value && is_reference_wrapper<std::decay_t<RefWrap>>::value,
32 decltype( ( ref.get().*pmf )( std::forward<Args>( args )... ) )>
33
34 {
35 return ( ref.get().*pmf )( std::forward<Args>( args )... );
36 }
37
38 template <class Base, class T, class Pointer, class... Args>
39 auto INVOKE( T Base::*pmf, Pointer&& ptr, Args&&... args ) noexcept(
40 noexcept( ( ( *std::forward<Pointer>( ptr ) ).*pmf )( std::forward<Args>( args )... ) ) )
41 -> std::enable_if_t<std::is_function<T>::value && !is_reference_wrapper<std::decay_t<Pointer>>::value &&
42 !std::is_base_of<Base, std::decay_t<Pointer>>::value,
43 decltype( ( ( *std::forward<Pointer>( ptr ) ).*pmf )( std::forward<Args>( args )... ) )>
44 {
45 return ( ( *std::forward<Pointer>( ptr ) ).*pmf )( std::forward<Args>( args )... );
46 }
47
48 template <class Base, class T, class Derived>
49 auto INVOKE( T Base::*pmd, Derived&& ref ) noexcept( noexcept( std::forward<Derived>( ref ).*pmd ) )
50 -> std::enable_if_t<!std::is_function<T>::value && std::is_base_of<Base, std::decay_t<Derived>>::value,
51 decltype( std::forward<Derived>( ref ).*pmd )>
52 {
53 return std::forward<Derived>( ref ).*pmd;
54 }
55
56 template <class Base, class T, class RefWrap>
57 auto INVOKE( T Base::*pmd, RefWrap&& ref ) noexcept( noexcept( ref.get().*pmd ) )
58 -> std::enable_if_t<!std::is_function<T>::value && is_reference_wrapper<std::decay_t<RefWrap>>::value,
59 decltype( ref.get().*pmd )>
60 {
61 return ref.get().*pmd;
62 }
63
64 template <class Base, class T, class Pointer>
65 auto INVOKE( T Base::*pmd, Pointer&& ptr ) noexcept( noexcept( ( *std::forward<Pointer>( ptr ) ).*pmd ) )
66 -> std::enable_if_t<!std::is_function<T>::value && !is_reference_wrapper<std::decay_t<Pointer>>::value &&
67 !std::is_base_of<Base, std::decay_t<Pointer>>::value,
68 decltype( ( *std::forward<Pointer>( ptr ) ).*pmd )>
69 {
70 return ( *std::forward<Pointer>( ptr ) ).*pmd;
71 }
72
73 template <class F, class... Args>
74 auto INVOKE( F&& f, Args&&... args ) noexcept( noexcept( std::forward<F>( f )( std::forward<Args>( args )... ) ) )
75 -> std::enable_if_t<!std::is_member_pointer<std::decay_t<F>>::value,
76 decltype( std::forward<F>( f )( std::forward<Args>( args )... ) )>
77 {
78 return std::forward<F>( f )( std::forward<Args>( args )... );
79 }
80 } // namespace detail2
81
82 template <class F, class... ArgTypes>
83 auto invoke( F&& f, ArgTypes&&... args )
84 // exception specification for QoI
85 noexcept( noexcept( detail2::INVOKE( std::forward<F>( f ), std::forward<ArgTypes>( args )... ) ) )
86 -> decltype( detail2::INVOKE( std::forward<F>( f ), std::forward<ArgTypes>( args )... ) )
87 {
88 return detail2::INVOKE( std::forward<F>( f ), std::forward<ArgTypes>( args )... );
89 }
90 }
gaudirun.args
args
Definition: gaudirun.py:244
std
STL namespace.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
Gaudi::detail2::INVOKE
auto INVOKE(T Base::*pmf, Derived &&ref, Args &&...args) noexcept( noexcept((std::forward< Derived >(ref).*pmf)(std::forward< Args >(args)...))) -> std::enable_if_t< std::is_function< T >::value &&std::is_base_of< Base, std::decay_t< Derived >>::value, decltype((std::forward< Derived >(ref).*pmf)(std::forward< Args >(args)...))>
Definition: invoke.h:20
Gaudi::detail2::is_reference_wrapper
Definition: invoke.h:13
GaudiPython.Persistency.get
def get(type_)
Definition: Persistency.py:29
std::false_type
Gaudi::invoke
auto invoke(F &&f, ArgTypes &&...args) noexcept(noexcept(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))) -> decltype(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))
Definition: invoke.h:83
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1