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