2018-05-12 14:28:23 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
#include "types/traits.hpp"
|
2017-09-08 14:20:01 +10:00
|
|
|
|
2017-12-28 17:48:21 +11:00
|
|
|
#include <list>
|
|
|
|
|
2017-09-08 14:20:01 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FuncT>
|
|
|
|
constexpr bool
|
|
|
|
returns_int (FuncT)
|
|
|
|
{
|
|
|
|
return std::is_same_v<
|
|
|
|
int,
|
|
|
|
typename func_traits<FuncT>::return_type
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename, class = std::void_t<>>
|
|
|
|
struct has_return_type : std::false_type {};
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
struct has_return_type<
|
|
|
|
T, std::void_t<typename func_traits<T>::return_type>
|
|
|
|
> : std::true_type {};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-10-11 17:15:47 +11:00
|
|
|
extern int plain (char, float) { return 0; }
|
|
|
|
extern int with_noexcept (char, float) noexcept { return 0; }
|
|
|
|
|
2017-09-08 14:20:01 +10:00
|
|
|
struct foo {
|
2017-10-11 17:15:47 +11:00
|
|
|
int bar (double, char) const { return 0; }
|
|
|
|
int with_noexcept (double, char) noexcept { return 0; }
|
2017-09-08 14:20:01 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2017-09-08 14:20:01 +10:00
|
|
|
|
|
|
|
tap.expect (returns_int ( plain), "free-function by-reference");
|
|
|
|
tap.expect (returns_int (&plain), "free-function by-pointer");
|
|
|
|
|
|
|
|
tap.expect (returns_int ( with_noexcept), "free-function with noexcept by-reference");
|
|
|
|
tap.expect (returns_int (&with_noexcept), "free-function with noexcept by-pointer");
|
|
|
|
|
|
|
|
tap.expect (returns_int (&foo::bar), "member-function by reference");
|
|
|
|
tap.expect (returns_int (&foo::with_noexcept), "member-function with noexcept by reference");
|
|
|
|
|
|
|
|
using all_t = void (*const &)(void *, unsigned int, unsigned int, void **) noexcept;
|
|
|
|
tap.expect (std::is_same_v<void, typename func_traits<all_t>::return_type>,
|
|
|
|
"complex function type");
|
|
|
|
|
|
|
|
tap.expect (!has_return_type<int>::value, "integer is not applicable to func_traits");
|
2017-12-28 17:48:21 +11:00
|
|
|
|
|
|
|
|
|
|
|
tap.expect (is_contiguous_v<std::vector<char>>, "vector is contiguous");
|
|
|
|
tap.expect (is_contiguous_v<std::array<char,4>>, "array is contiguous");
|
|
|
|
tap.expect (!is_contiguous_v<std::list<char>>, "list is not contiguous");
|
2018-08-01 18:39:01 +10:00
|
|
|
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::is_same_basic_type_v<float,double>, "float-double same_basic_type");
|
|
|
|
tap.expect (!cruft::is_same_basic_type_v<float,int>, "float-int same_basic_type");
|
2017-12-28 17:48:21 +11:00
|
|
|
return tap.status ();
|
2017-09-08 14:20:01 +10:00
|
|
|
}
|