Tinvoke.cpp
Go to the documentation of this file.
#include <utl/utility/invoke.h>
#include <gtest/gtest.h>
#include <type_traits>
namespace test_meta {
using namespace utl;
/*
* Types to behave like Fixtures
*/
int Ifun(int i) { return i; }
struct Ifoo {
int operator() (int i) {
return i;
}
};
struct Ibar {
Ibar(int num) : num_(num) {}
int echo(int i) const { return i; }
int get() const { return num_; }
int num_;
};
/*
* Test invoke()
*/
TEST(Tinvoke, Invoke) {
Ifoo ifoo{};
const Ibar ibar{42};
EXPECT_EQ (42, invoke(Ifun, 42));
EXPECT_EQ (42, invoke([] () { return Ifun(42); }));
EXPECT_EQ (42, invoke(Ifoo{}, 42));
EXPECT_EQ (42, invoke(ifoo, 42));
EXPECT_EQ (42, invoke(&Ibar::echo, ibar, 42));
EXPECT_EQ (42, invoke(&Ibar::get, ibar));
EXPECT_EQ (true, (is_invocable<Ifoo, int>::value));
EXPECT_EQ (false, (is_invocable<Ifoo>::value));
EXPECT_EQ (false, (is_invocable<Ifoo, int, double>::value));
EXPECT_EQ (false, (is_invocable<Ibar, int>::value));
EXPECT_EQ (true, (is_invocable_r<int, Ifoo, int>::value));
EXPECT_EQ (false, (is_invocable_r<int*, Ifoo, int>::value));
EXPECT_EQ (false, (is_invocable_r<int, Ifoo>::value));
EXPECT_EQ (true, (std::is_same<int, invoke_result_t<Ifoo, int>>()));
EXPECT_EQ (true, (std::is_same<meta::nil_, invoke_result_t<Ifoo>>()));
EXPECT_EQ (true, (std::is_same<meta::nil_, invoke_result_t<Ifoo, int, double>>()));
}
}
test_meta::Ifoo
Definition: Tinvoke.cpp:31
test_meta::Ibar::echo
int echo(int i) const
Definition: Tinvoke.cpp:39
test_meta
Definition: Tinvoke.cpp:24
gtest.h
test_meta::Ibar::Ibar
Ibar(int num)
Definition: Tinvoke.cpp:38
utl::meta::nil_
Definition: integral.h:43
invoke.h
invoke() and invoke traits implementation
test_meta::TEST
TEST(Tinvoke, Invoke)
Definition: Tinvoke.cpp:47
utl
STL&#39;s core language concepts.
Definition: _1wire.h:30
test_meta::Ifun
int Ifun(int i)
Definition: Tinvoke.cpp:30
test_meta::Ibar
Definition: Tinvoke.cpp:37
utl::invoke_result_t
meta::eval< invoke_result< _Callable, _Args... > > invoke_result_t
invoke_result_t (for C++14)
Definition: invoke.h:180
utl::is_invocable_r
std::is_invocable_r trait for C++11
Definition: invoke.h:138
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
utl::meta::invoke
typename Fn::template apply< Args... > invoke
Definition: invoke.h:81
test_meta::Ibar::num_
int num_
Definition: Tinvoke.cpp:41
test_meta::Ibar::get
int get() const
Definition: Tinvoke.cpp:40
utl::is_invocable
std::is_invocable trait for C++11
Definition: invoke.h:130