1// SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#include "function_traits.h"
5
6// Tests for function_traits<>
7
8using namespace Quotient;
9
10template <typename FnT>
11using fn_return_t = typename function_traits<FnT>::return_type;
12
13int f_();
14static_assert(std::is_same_v<fn_return_t<decltype(f_)>, int>,
15 "Test fn_return_t<>");
16
17void f1_(int, float);
18static_assert(std::is_same_v<fn_arg_t<decltype(f1_), 1>, float>,
19 "Test fn_arg_t<>");
20
21struct Fo {
22 int operator()();
23 static constexpr auto l = [] { return 0.0f; };
24 bool memFn();
25 void constMemFn() const&;
26 double field;
27 const double field2;
28};
29static_assert(std::is_same_v<fn_return_t<Fo>, int>,
30 "Test return type of function object");
31static_assert(std::is_same_v<fn_return_t<decltype(Fo::l)>, float>,
32 "Test return type of lambda");
33static_assert(std::is_same_v<fn_arg_t<decltype(&Fo::memFn)>, Fo>,
34 "Test first argument type of member function");
35static_assert(std::is_same_v<fn_return_t<decltype(&Fo::memFn)>, bool>,
36 "Test return type of member function");
37static_assert(std::is_same_v<fn_arg_t<decltype(&Fo::constMemFn)>, const Fo&>,
38 "Test first argument type of const member function");
39static_assert(std::is_void_v<fn_return_t<decltype(&Fo::constMemFn)>>,
40 "Test return type of const member function");
41static_assert(std::is_same_v<fn_return_t<decltype(&Fo::field)>, double&>,
42 "Test return type of a class member");
43static_assert(std::is_same_v<fn_return_t<decltype(&Fo::field2)>, const double&>,
44 "Test return type of a const class member");
45
46struct Fo1 {
47 void operator()(int);
48};
49static_assert(std::is_same_v<fn_arg_t<Fo1>, int>,
50 "Test fn_arg_t defaulting to first argument");
51
52template <typename T>
53[[maybe_unused]] static void ft(const std::vector<T>&);
54static_assert(
55 std::is_same<fn_arg_t<decltype(ft<double>)>, const std::vector<double>&>(),
56 "Test function templates");
57