libzypp 17.37.10

functional.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPPNG_META_FUNCTIONAL_H_INCLUDED
15#define ZYPPNG_META_FUNCTIONAL_H_INCLUDED
16
17#include <functional>
18
19#if __cplusplus <= 201402L || !defined ( __cpp_lib_invoke )
20
21#include <type_traits>
22
23// this is a workaround for std::invoke not being available in C++14
24// and the proposed minimal implementation in
25// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4169.html
26
27 namespace std {
28 template<typename Functor, typename... Args>
29 typename std::enable_if<
30 std::is_member_pointer<typename std::decay<Functor>::type>::value,
31 typename std::result_of<Functor&&(Args&&...)>::type
32 >::type invoke(Functor&& f, Args&&... args)
33 {
34 return std::mem_fn(f)(std::forward<Args>(args)...);
35 }
36
37 template<typename Functor, typename... Args>
38 typename std::enable_if<
39 !std::is_member_pointer<typename std::decay<Functor>::type>::value,
40 typename std::result_of<Functor&&(Args&&...)>::type
41 >::type invoke(Functor&& f, Args&&... args)
42 {
43 return std::forward<Functor>(f)(std::forward<Args>(args)...);
44 }
45}
46
47#endif
48
53 template<typename Obj, typename Ret, typename Arg>
54 auto mem_fn_cb( Obj& o, Ret (Obj::*objMemFunc)( Arg&& ) ) {
55 return [tPtr = &o, fun = objMemFunc ]( Arg &&r ){
56 return std::invoke(fun, tPtr, std::move(r) );
57 };
58}
59
60 template<typename Obj, typename Ret, typename Arg>
61 auto mem_fn_cb( Obj& o, Ret (Obj::*objMemFunc)( const Arg& ) ) {
62 return [tPtr = &o, fun = objMemFunc ]( const Arg &r ){
63 return std::invoke(fun, tPtr, r );
64 };
65}
66
67 template<typename Obj, typename Ret, typename Arg>
68 auto mem_fn_cb( Obj& o, Ret (Obj::*objMemFunc)( Arg ) ) {
69 return [tPtr = &o, fun = objMemFunc ]( Arg r ){
70 if constexpr ( std::is_invocable_v< decltype (fun), Obj*, Arg&&> ) {
71 return std::invoke(fun, tPtr, std::move(r) );
72 } else {
73 return std::invoke(fun, tPtr, r );
74 }
75 };
76}
77
78
79#endif
mem_fn_cb
auto mem_fn_cb(Obj &o, Ret(Obj::*objMemFunc)(Arg &&))
Definition functional.h:54
std
Definition Arch.h:364
std::invoke
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition functional.h:32