uTL
micro Template library
Tinvoke.cpp
Go to the documentation of this file.
1 
20 #include <utl/utility/invoke.h>
21 #include <gtest/gtest.h>
22 #include <type_traits>
23 
24 namespace test_meta {
25  using namespace utl;
26 
27  /*
28  * Types to behave like Fixtures
29  */
30  int Ifun(int i) { return i; }
31  struct Ifoo {
32  int operator() (int i) {
33  return i;
34  }
35  };
36 
37  struct Ibar {
38  Ibar(int num) : num_(num) {}
39  int echo(int i) const { return i; }
40  int get() const { return num_; }
41  int num_;
42  };
43 
44  /*
45  * Test invoke()
46  */
47  TEST(Tinvoke, Invoke) {
48  Ifoo ifoo{};
49  const Ibar ibar{42};
50 
51  EXPECT_EQ (42, invoke(Ifun, 42));
52  EXPECT_EQ (42, invoke([] () { return Ifun(42); }));
53  EXPECT_EQ (42, invoke(Ifoo{}, 42));
54  EXPECT_EQ (42, invoke(ifoo, 42));
55  EXPECT_EQ (42, invoke(&Ibar::echo, ibar, 42));
56  EXPECT_EQ (42, invoke(&Ibar::get, ibar));
57 
62 
66 
67  EXPECT_EQ (true, (std::is_same<int, invoke_result_t<Ifoo, int>>()));
68  EXPECT_EQ (true, (std::is_same<meta::nil_, invoke_result_t<Ifoo>>()));
69  EXPECT_EQ (true, (std::is_same<meta::nil_, invoke_result_t<Ifoo, int, double>>()));
70 
71  }
72 }
int echo(int i) const
Definition: Tinvoke.cpp:39
Ibar(int num)
Definition: Tinvoke.cpp:38
invoke() and invoke traits implementation
TEST(Tinvoke, Invoke)
Definition: Tinvoke.cpp:47
STL&#39;s core language concepts.
Definition: _1wire.h:30
int Ifun(int i)
Definition: Tinvoke.cpp:30
meta::eval< invoke_result< _Callable, _Args... > > invoke_result_t
invoke_result_t (for C++14)
Definition: invoke.h:180
std::is_invocable_r trait for C++11
Definition: invoke.h:138
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
typename Fn::template apply< Args... > invoke
Definition: invoke.h:81
int get() const
Definition: Tinvoke.cpp:40
std::is_invocable trait for C++11
Definition: invoke.h:130