Skip to content
Snippets Groups Projects
Commit b28d482a authored by Recolic K's avatar Recolic K
Browse files

remote traitshpp

parent 4c669bb4
No related branches found
No related tags found
No related merge requests found
Pipeline #899 failed with stage
#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 {
......
......@@ -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) {
......
......@@ -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; }
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment