Is it still possible to customize STL vector's “reference” type?

前端 未结 1 799
北海茫月
北海茫月 2021-01-15 06:16

Is it possible to customize the reference of a std::vector. Until C++11 it seemed to be possible through the Allocator template param

相关标签:
1条回答
  • 2021-01-15 06:49

    If this is so, generally speaking what is the logic for all these constrains?

    The purpose is to stop promising things C++ cannot deliver.

    Back in the C++98/03 days, it was thought that proxy types, specialized references and the like could really work with standard library containers and algorithms. By the time C++11 rolled around, it had become abundantly clear that... no, they really can't. Or at least, not with the same semantics as an actual language reference.

    With that wisdom in mind, C++11 removed a lot of these no-longer-reasonable customization points. The typedefs were left in, but mainly for backwards-compatibility's sake.

    which seems to indicate that it is still possible to specify a reference type via the allocator (_traits?).

    No, it isn't. This is a bug in libstdc++; reference is required to be value_type& for containers now. allocator_traits has no reference customization point.

    0 讨论(0)
提交回复
热议问题