#include "kblib/fakestd.h" #include "catch.hpp" template struct Ref { auto operator->() -> auto { return kblib::meta_type_t{}; } // present only if sizeof...(Args) == 1 }; // static decltype(&Ref::operator->) f; // static decltype(&Ref::operator->) f2; static Ref r; KBLIB_UNUSED static Ref r2; KBLIB_UNUSED static auto blah() -> void { r.operator->(); // r2.operator->(); std::tuple a{0, 0}, b{0, 1}; kblib::swap(a, b); } TEST_CASE("to_unique(lambda)") { // to_unique can make unique_ptrs to anonymous types auto p = kblib::to_unique(new auto([] {}), [](auto* p) { delete p; }); } TEST_CASE("signed_cast") { REQUIRE(kblib::signed_cast(-1ll) == -1ull); REQUIRE(kblib::signed_cast(static_cast(78)) == 78); static_assert( std::is_same( std::declval()))>::value, ""); static_assert(std::is_same( std::declval()))>::value, ""); static_assert(std::is_same( std::declval()))>::value, ""); static_assert(std::is_same( std::declval()))>::value, ""); static_assert( std::is_same( std::declval()))>::value, ""); // auto _1 = kblib::signed_cast(0.0); // auto _2 = kblib::signed_cast(0); } #if KBLIB_USE_CXX17 template KBLIB_UNUSED constexpr auto type_name_f() -> std::string_view { using namespace std; # ifdef __clang__ string_view p = __PRETTY_FUNCTION__; return string_view(p.data() + 36, p.size() - 36 - 1); # elif defined(__GNUC__) string_view p = __PRETTY_FUNCTION__; # if __cplusplus < 201402 return string_view(p.data() + 36, p.size() - 36 - 1); # else return string_view(p.data() + 49, p.find(';', 49) - 49); # endif # elif defined(_MSC_VER) string_view p = __FUNCSIG__; return string_view(p.data() + 84, p.size() - 84 - 7); # endif } #endif #if KBLIB_USE_CXX17 TEST_CASE("next_larger") { static_assert( std::is_same::type, short>::value, "signed char < short"); static_assert( std::is_same::type, int>::value, "short < int"); static_assert( std::is_same::type, long>::value, "int < long"); # if 0 std::cout << "Next_larger: \n" << "signed char: " << type_name_f::type>() << '\n' << "short: " << type_name_f::type>() << '\n' << "int: " << type_name_f::type>() << '\n'; // long long can't be promoted // std::cout // << "long long: " // << type_name_f::type>() // << '\n'; # endif } #endif