Relative Content

Tag Archive for c++templatesc++20sfinae

Check for the existence of a template function in c++

#include <type_traits> template <typename Allocator> struct AllocatorTraits { private: template <typename U> static auto malloc(int) -> decltype(static_cast<void* (U::*)(size_t)>(&U::malloc), std::true_type()); template <typename> static std::false_type malloc(…); template <typename U, typename T, typename… Args> static auto allocate(int) -> decltype(static_cast<T* (U::*)(Args…)>(&U::template allocate<T, Args…>), std::true_type()); template <typename> static std::false_type allocate(…); public: static constexpr bool has_malloc = decltype(malloc<Allocator>(0))::value; template <typename T, […]

Check for the existence of a template function in c++

#include <type_traits> template <typename Allocator> struct AllocatorTraits { private: template <typename U> static auto malloc(int) -> decltype(static_cast<void* (U::*)(size_t)>(&U::malloc), std::true_type()); template <typename> static std::false_type malloc(…); template <typename U, typename T, typename… Args> static auto allocate(int) -> decltype(static_cast<T* (U::*)(Args…)>(&U::template allocate<T, Args…>), std::true_type()); template <typename> static std::false_type allocate(…); public: static constexpr bool has_malloc = decltype(malloc<Allocator>(0))::value; template <typename T, […]