From b28d482ada304bc914f4e7c13c4bc0c4b800f783 Mon Sep 17 00:00:00 2001 From: Recolic K <bensl@microsoft.com> Date: Tue, 14 Jun 2022 18:03:54 +0800 Subject: [PATCH] remote traitshpp --- meta.hpp | 36 +++++++++++++++++++++++++++++-- test/src/common.cc | 2 +- test/src/header-include-all.cc | 2 +- traits.hpp | 39 ---------------------------------- 4 files changed, 36 insertions(+), 43 deletions(-) delete mode 100644 traits.hpp diff --git a/meta.hpp b/meta.hpp index 96e6048..83022ff 100644 --- a/meta.hpp +++ b/meta.hpp @@ -1,10 +1,42 @@ -#ifndef RLIB_MEelement_typeA_HPP_ -#define RLIB_MEelement_typeA_HPP_ +#ifndef RLIB_META_HPP_ +#define RLIB_META_HPP_ #include <rlib/sys/os.hpp> #include <cstddef> // size_t #include <tuple> +#include <type_traits> + +namespace rlib { + namespace impl { + template<typename T> + struct is_callable_helper { + private: + typedef char(&yes)[1]; + typedef char(&no)[2]; + + struct Fallback { void operator()(); }; + struct Derived : T, Fallback { }; + + template<typename U, U> struct Check; + + template<typename> + static yes test(...); + + template<typename C> + static no test(Check<void (Fallback::*)(), &C::operator()>*); + + static constexpr bool value = sizeof(test<Derived>(0)) == sizeof(yes); + public: + static constexpr bool real_value = std::conditional<std::is_class<T>::value, impl::is_callable_helper<T>, std::is_function<T>>::type::value; + }; + } + template<typename T> + struct is_callable : public std::integral_constant<bool, impl::is_callable_helper<T>::real_value> { + }; +} // end namespace rlib + + namespace rlib { #if RLIB_CXX_STD >= 2017 namespace impl { diff --git a/test/src/common.cc b/test/src/common.cc index 946908f..709e228 100644 --- a/test/src/common.cc +++ b/test/src/common.cc @@ -17,7 +17,7 @@ public: #if RLIB_CXX_STD >= 2017 #include <rlib/functional.hpp> -#include <rlib/traits.hpp> +#include <rlib/meta.hpp> TEST_CASE("functional") { std::stringstream test_ss; auto test_func = [&](int i) { diff --git a/test/src/header-include-all.cc b/test/src/header-include-all.cc index 5c11f18..d769610 100644 --- a/test/src/header-include-all.cc +++ b/test/src/header-include-all.cc @@ -26,6 +26,6 @@ #include <rlib/stdio.hpp> #include <rlib/stream.hpp> #include <rlib/terminal.hpp> -#include <rlib/traits.hpp> +#include <rlib/meta.hpp> int main() { return 0; } diff --git a/traits.hpp b/traits.hpp deleted file mode 100644 index 8b14670..0000000 --- a/traits.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RLIB_TRAITS_HPP -#define RLIB_TRAITS_HPP - -#include <rlib/require/cxx11> -#include <type_traits> - -namespace rlib{ - namespace impl { - template<typename T> - struct is_callable_helper { - private: - typedef char(&yes)[1]; - typedef char(&no)[2]; - - struct Fallback { void operator()(); }; - struct Derived : T, Fallback { }; - - template<typename U, U> struct Check; - - template<typename> - static yes test(...); - - template<typename C> - static no test(Check<void (Fallback::*)(), &C::operator()>*); - - static constexpr bool value = sizeof(test<Derived>(0)) == sizeof(yes); - public: - static constexpr bool real_value = std::conditional<std::is_class<T>::value, impl::is_callable_helper<T>, std::is_function<T>>::type::value; - }; - } //impl -} //rlib - -namespace rlib { - template<typename T> - struct is_callable : public std::integral_constant<bool, impl::is_callable_helper<T>::real_value> { - }; -} - -#endif -- GitLab