diff --git a/CMakeLists.txt b/CMakeLists.txt index afae28d3..9711e82d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -507,6 +507,7 @@ if (TESTS) stringid strongdef tuple + traits typeidx uri vector diff --git a/test/traits.cpp b/test/traits.cpp new file mode 100644 index 00000000..674a9f86 --- /dev/null +++ b/test/traits.cpp @@ -0,0 +1,58 @@ +#include +#include + + +/////////////////////////////////////////////////////////////////////////////// +template +constexpr bool +returns_int (FuncT) +{ + return std::is_same_v< + int, + typename func_traits::return_type + >; +} + + +/////////////////////////////////////////////////////////////////////////////// +template > +struct has_return_type : std::false_type {}; + + +//----------------------------------------------------------------------------- +template +struct has_return_type< + T, std::void_t::return_type> +> : std::true_type {}; + + +/////////////////////////////////////////////////////////////////////////////// +int plain (char, float); +int with_noexcept (char, float) noexcept; +struct foo { + int bar (double, char) const; + int with_noexcept (double, char) noexcept; +}; + + +/////////////////////////////////////////////////////////////////////////////// +int +main (void) +{ + util::TAP::logger tap; + + 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::return_type>, + "complex function type"); + + tap.expect (!has_return_type::value, "integer is not applicable to func_traits"); +} \ No newline at end of file