我最近尝试研究libstdc ++源代码(GCC 7.2)并且感到困惑。可能我错过了一些重要的东西,但我开始认为实现完全符合C ++标准的basic_string类是不可能的。
这是我遇到的一个问题。
第4项和第5项是冲突的,我不知道如何解决它。希望你能帮助我搞清楚。
谢谢!
该标准有几个要求,它们总是确保转换是可能的,至少是间接的
basic_string<charT, traits, Allocator>
,the standard requires charT
和allocator_traits<Allocator>::value_type
是平等的。allocator_traits<Allocator>::pointer
is required,Allocator::pointer
Allocator::value_type*
为Allocator::pointer
。
在后一种情况下,一切都是微不足道的。p
*p
是一个is required,这要求,给定一个连续的迭代器Allocator::value_type&
,Allocator::pointer
q
*(q + n) == *(addressof(*q) + n)
返回Allocator
。将所有内容组合在一起,就意味着这始终是正确的
a
a.allocate(n)
可能存储前一次调用is required的结果