Код: Выделить всё
#include
template
struct AllocatorTraits {
private:
template
static auto malloc(int) -> decltype(static_cast(&U::malloc), std::true_type());
template
static std::false_type malloc(...);
template
static auto allocate(int) -> decltype(static_cast(&U::template allocate), std::true_type());
template
static std::false_type allocate(...);
public:
static constexpr bool has_malloc = decltype(malloc(0))::value;
template
static constexpr bool has_allocate = decltype(allocate(0))::value;
};
class TestClass {
public:
void* malloc(size_t size) noexcept { return nullptr; }
template
T* allocate(Args &&...args) noexcept { return nullptr; }
};
static constexpr bool test_malloc = AllocatorTraits::has_malloc;
static constexpr bool test_allocate = AllocatorTraits::has_allocate;
Код: Выделить всё
TestClass::allocate (error C2672: 'AllocatorTraits::allocate': no matching overloaded function found).
Подробнее здесь: https://stackoverflow.com/questions/793 ... ction-in-c