diff --git a/meta.hpp b/meta.hpp index 96e6048948a190e95345c4df28ae2161581398a6..83022ff65da3cfb682d874c95d5028e9b975bafb 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 946908f32f62da9a4fe1544e90f5cb7ea82a152a..709e228247ae6c6dca144d749a57113f5a105733 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 5c11f18b2feb0e204b40a15a62c9962a182de3bf..d76961070663ce81a87669198045bf55f219b77d 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 8b146706be7f42863bd398194eda6e395a48e7e2..0000000000000000000000000000000000000000 --- 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