で行われる割り当てに特化した最適化を提供したいのですstd::allocator
が、誰かがまたはをオーバーライドせずにサブクラス化した場合、それらがまだ使用されているかどうかを検出する方法がわかりません。allocate
deallocate
std::allocator
どうすればよいですか?
独自の関数allocate
とdeallocate
関数を定義していないと仮定すると、テストする1つの方法は、値をテストすることです。
is_default_allocator_allocation<allocator_type>::value
allocate
およびdeallocate
メソッドがデフォルトのものであるかどうかをテストします。
それらが独自の機能を提供している場合、テストする一般的な方法はありません。
このソリューションでは、他の方法は考慮されていません。
それはあなたに時折の誤検知を与える可能性がありますが、誤検知を与えるべきではありません。
私の実装:
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);
};