当然,看起来像这样:
#include <type_traits>
template <class T>
struct is_const_method
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...)>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const>
: std::true_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) volatile>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const volatile>
: std::true_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) &>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const &>
: std::true_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) volatile &>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const volatile &>
: std::true_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) &&>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const &&>
: std::true_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) volatile &&>
: std::false_type
{
};
template <class R, class C, class ...T>
struct is_const_method<R (C::*)(T...) const volatile &&>
: std::true_type
{
};
struct foo {
void dummy() const {}
};
int main()
{
static_assert(is_const_method<decltype(&foo::dummy)>::value, "Not const!");
}