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

和自甴很熟 提交于 2019-12-01 11:27:34

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!