C++ 如何测试分配器是否使用std::allocate进行内存分配?
我想为使用C++ 如何测试分配器是否使用std::allocate进行内存分配?,c++,allocator,C++,Allocator,我想为使用std::allocator完成的分配提供专门的优化,但是如果有人在没有覆盖allocate或deallocate的情况下对其进行了子类化,那么我不知道如何检测他们是否仍在使用std::allocator 我该怎么做呢?假设他们没有定义自己的分配和解除分配函数,那么测试的一种方法就是测试值 is_default_allocator_allocation<allocator_type>::value template<class Ax> char (&i
std::allocator
完成的分配提供专门的优化,但是如果有人在没有覆盖allocate
或deallocate
的情况下对其进行了子类化,那么我不知道如何检测他们是否仍在使用std::allocator
我该怎么做呢?假设他们没有定义自己的
分配
和解除分配
函数,那么测试的一种方法就是测试值
is_default_allocator_allocation<allocator_type>::value
template<class Ax> char (&is_default_deallocate(void (std::allocator<typename Ax::value_type>::*)(typename Ax::pointer, typename Ax::size_type)))[1];
template<class Ax> char (&is_default_deallocate(void (Ax::*)(typename Ax::pointer, typename Ax::size_type)))[2];
template<class Ax> char (&is_default_allocate(typename Ax::pointer (std::allocator<typename Ax::value_type>::*)(typename Ax::size_type, void const *)))[1];
template<class Ax> char (&is_default_allocate(typename Ax::pointer (Ax::*)(typename Ax::size_type, void const *)))[2];
template<class Ax>
struct is_default_allocator_allocation // tests allocate() and deallocate()
{
static bool const value =
sizeof(is_default_deallocate<Ax>(&Ax::deallocate)) == sizeof(char)
&& sizeof(is_default_allocate<Ax>(&Ax::allocate)) == sizeof(char);
};