| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

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