Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何测试分配器是否使用std::allocate进行内存分配?_C++_Allocator - Fatal编程技术网

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);
};