Libsaki
Core library of Pancake Mahjong
dismember.h
1 #ifndef SAKI_DISMEMBER_H
2 #define SAKI_DISMEMBER_H
3 
4 #include <type_traits>
5 #include <utility>
6 
7 
8 
9 namespace saki
10 {
11 
12 
13 
18 template<typename Class>
19 class PredThis
20 {
21 public:
22  constexpr explicit PredThis(bool (Class::*predMem)() const) noexcept
23  : mPredMem(predMem)
24  {
25  }
26 
27  bool operator()(const Class &thiz)
28  {
29  return (thiz.*mPredMem)();
30  }
31 
32 private:
33  bool (Class::*mPredMem)() const;
34 };
35 
36 template<typename Class, typename Ret, typename... Args>
38 {
39 public:
40  using Method = Ret (Class::*)(Args...) const;
41 
42  explicit ReturnCopy(Method method)
43  : mMethod(method)
44  {
45  }
46 
47  std::remove_reference_t<Ret> operator()(Class &thiz, Args &&... args)
48  {
49  return (thiz.*mMethod)(std::forward<Args>(args)...);
50  }
51 
52 private:
53  Method mMethod;
54 };
55 
56 
57 
58 
59 } // namespace saki
60 
61 
62 
63 #endif // SAKI_DISMEMBER_H
Definition: ai.cpp:18
Definition: dismember.h:19
Definition: dismember.h:37