std :: listのgcc実装のようです。その場合には、コンテキストは次のとおりです。
struct _List_impl : public _Node_Alloc_type { ... };
_List_impl _M_impl;
そして、あなたは、メンバ関数の戻り値の型書くのを忘れ:追加する場合は(1)
ため
typedef _Alloc allocator_type;
allocator_type
get_allocator() const
{ return allocator_type(*static_cast<const _Node_Alloc_type*>(&this->_M_impl)); }
回答ノードがリスト_Tp
のリスト内にある場合、実際に割り当てられる必要があるのはオブジェクト_Tp
ではなく、_Tp
(a _List_node<_Tp>
)を含むリストノードです。
したがって、std :: listは_List_node<_Tp>
を割り当てる必要がありますが、_Tp
のアロケータが提供されています。これはテンプレートtypedefの再バインドが便利な点です。タイプUのアロケータをタイプTのアロケータから取得することができます。
この再バインドを使用して、タイプ_Alloc<_Tp>
から_Alloc<_List_node<_Tp> >
を取得します。(2)コメントとしてソースファイルにするための
回答:
// NOTA BENE
// The stored instance is not actually of "allocator_type"'s
// type. Instead we rebind the type to
// Allocator<List_node<Tp>>, which according to [20.1.5]/4
// should probably be the same. List_node<Tp> is not the same
// size as Tp (it's two pointers larger), and specializations on
// Tp may go unused because List_node<Tp> is being bound
// instead.
//
// We put this to the test in the constructors and in
// get_allocator, where we use conversions between
// allocator_type and _Node_Alloc_type. The conversion is
// required by table 32 in [20.1.5].
_Alloc
のタイプはC++標準の通り_Node_Alloc_type
と同じであると仮定されます。したがって、static_castは変換が合法であると主張します。
あなたが見ているSTLの具体的な実装を明確にする必要があります。 STLインターフェイスは標準化されていますが、実装はベンダーごとに異なります。 –