qswiki/database/hdr/sqlite_modern_cpp/utility/function_traits.h

56 lines
1.2 KiB
C
Raw Normal View History

2018-11-03 17:12:20 +01:00
#pragma once
#include <tuple>
#include<type_traits>
namespace sqlite {
namespace utility {
template<typename> struct function_traits;
template <typename Function>
struct function_traits : public function_traits<
decltype(&std::remove_reference<Function>::type::operator())
> { };
template <
2019-09-30 20:20:41 +02:00
typename ClassType,
typename ReturnType,
2018-11-03 17:12:20 +01:00
typename... Arguments
>
struct function_traits<
ReturnType(ClassType::*)(Arguments...) const
> : function_traits<ReturnType(*)(Arguments...)> { };
2019-09-30 20:20:41 +02:00
/* support the non-const operator ()
* this will work with user defined functors */
2018-11-03 17:12:20 +01:00
template <
2019-09-30 20:20:41 +02:00
typename ClassType,
typename ReturnType,
2018-11-03 17:12:20 +01:00
typename... Arguments
>
struct function_traits<
ReturnType(ClassType::*)(Arguments...)
> : function_traits<ReturnType(*)(Arguments...)> { };
template <
2019-09-30 20:20:41 +02:00
typename ReturnType,
2018-11-03 17:12:20 +01:00
typename... Arguments
>
struct function_traits<
ReturnType(*)(Arguments...)
> {
typedef ReturnType result_type;
template <std::size_t Index>
using argument = typename std::tuple_element<
Index,
std::tuple<Arguments...>
>::type;
static const std::size_t arity = sizeof...(Arguments);
};
}
}