1 // Copyright 2015, Tobias Hermann and the FunctionalPlus contributors.
2 // https://github.com/Dobiasd/FunctionalPlus
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <doctest/doctest.h>
8 #include <fplus/fplus.hpp>
9 #include <vector>
10
11 namespace {
12
13 typedef std::deque<int> IntDeq;
14 typedef std::deque<IntDeq> IntContCont;
15 typedef IntDeq IntCont;
16 typedef IntCont Row;
17 }
18
CcI2SFree(const std::string & str,int x)19 std::string CcI2SFree(const std::string& str, int x)
20 {
21 return str + std::to_string(x);
22 }
23
24 auto CcI2SLambda = [](const std::string& str, int x)
__anonc5fc5b910202(const std::string& str, int x) 25 { return CcI2SFree(str, x); };
26
27 std::function<std::string(const std::string&, int)>
28 CcI2SStdFunction = CcI2SLambda;
29
30 std::string (*CcI2SFunctionPointer)(const std::string&, int) =
31 &CcI2SFree;
32
33 struct CcI2SStrct {
operator ()CcI2SStrct34 std::string operator() (const std::string& str, int x)
35 { return CcI2SFree(str, x); }
nonCMemFCcI2SStrct36 std::string nonCMemF (const std::string& str, int x)
37 { return CcI2SFree(str, x); }
cnstMemFCcI2SStrct38 std::string cnstMemF (const std::string& str, int x) const
39 { return CcI2SFree(str, x); }
sttcMemFCcI2SStrct40 static std::string sttcMemF (const std::string& str, int x)
41 { return CcI2SFree(str, x); }
42 };
43
44 TEST_CASE("function_traits_test - static_asserts")
45 {
46 using namespace fplus;
47 static_assert(std::is_same<
48 utils::function_traits<decltype(CcI2SFree)>::arg<0>::type,
49 const std::string&>::value, "No.");
50 static_assert(std::is_same<
51 utils::function_traits<decltype(CcI2SFree)>::arg<1>::type,
52 int>::value, "No.");
53 static_assert(std::is_same<
54 utils::function_traits<decltype(CcI2SFree)>::result_type,
55 std::string>::value, "No.");
56
57 static_assert(std::is_same<
58 utils::function_traits<decltype(CcI2SLambda)>::arg<0>::type,
59 const std::string&>::value, "No.");
60 static_assert(std::is_same<
61 utils::function_traits<decltype(CcI2SLambda)>::arg<1>::type,
62 int>::value, "No.");
63 static_assert(std::is_same<
64 utils::function_traits<decltype(CcI2SLambda)>::result_type,
65 std::string>::value, "No.");
66
67 static_assert(std::is_same<
68 utils::function_traits<decltype(CcI2SStdFunction)>::arg<0>::type,
69 const std::string&>::value, "No.");
70 static_assert(std::is_same<
71 utils::function_traits<decltype(CcI2SStdFunction)>::arg<1>::type,
72 int>::value, "No.");
73 static_assert(std::is_same<
74 utils::function_traits<decltype(CcI2SStdFunction)>::result_type,
75 std::string>::value, "No.");
76
77 static_assert(std::is_same<
78 utils::function_traits<decltype(CcI2SFunctionPointer)>::arg<0>::type,
79 const std::string&>::value, "No.");
80 static_assert(std::is_same<
81 utils::function_traits<decltype(CcI2SFunctionPointer)>::arg<1>::type,
82 int>::value, "No.");
83 static_assert(std::is_same<
84 utils::function_traits<decltype(CcI2SFunctionPointer)>::result_type,
85 std::string>::value, "No.");
86
87 CcI2SStrct ccI2SStrct;
88 ccI2SStrct("dummy call to avoid unused variable warnings", 0);
89 static_assert(std::is_same<
90 utils::function_traits<decltype(ccI2SStrct)>::arg<0>::type,
91 const std::string&>::value, "No.");
92 static_assert(std::is_same<
93 utils::function_traits<decltype(ccI2SStrct)>::arg<1>::type,
94 int>::value, "No.");
95 static_assert(std::is_same<
96 utils::function_traits<decltype(ccI2SStrct)>::result_type,
97 std::string>::value, "No.");
98
99 static_assert(std::is_same<
100 utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::arg<0>::type,
101 const std::string&>::value, "No.");
102 static_assert(std::is_same<
103 utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::arg<1>::type,
104 int>::value, "No.");
105 static_assert(std::is_same<
106 utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::result_type,
107 std::string>::value, "No.");
108
109 static_assert(std::is_same<
110 utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::arg<0>::type,
111 const std::string&>::value, "No.");
112 static_assert(std::is_same<
113 utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::arg<1>::type,
114 int>::value, "No.");
115 static_assert(std::is_same<
116 utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::result_type,
117 std::string>::value, "No.");
118
119 static_assert(std::is_same<
120 utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::arg<0>::type,
121 const std::string&>::value, "No.");
122 static_assert(std::is_same<
123 utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::arg<1>::type,
124 int>::value, "No.");
125 static_assert(std::is_same<
126 utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::result_type,
127 std::string>::value, "No.");
128 }
129