C++03 在获取分配器的上下文中相当于 auto
auto source_allocator = source.get_allocator();
如果事先不知道分配器的类型,是否有办法将上面的 auto
替换为 C++03/98 友好的内容?
auto source_allocator = source.get_allocator();
Is there a way of replacing auto
in the above with something C++03/98-friendly, in the event where the type of allocator is not known in advance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您在评论中发布的内容,听起来您正在尝试在模板中执行此操作。
假设您希望模板类型是 std::container 或兼容的东西,您可以这样做:
typename T::allocator_type
代替 auto。https://godbolt.org/z/Pda77vjox
Based on what you posted in the comments, it sounds like you're trying to do this inside a template.
Assuming you are expecting your templated type to be a std::container, or something compatible, you can do this:
typename T::allocator_type
in place of auto.https://godbolt.org/z/Pda77vjox
至少对于标准容器来说,容器类型需要定义
container_type
,因此您通常会得到以下一般顺序的结果:这正是他们要求标准容器来处理的情况。定义这些名称。当然,它也可以与其他具有相同功能的容器一起正常工作。
At least for standard containers, the container type is required to define
container_type
, so you'd normally end up with something on this general order:This is exactly the sort of situation for which they required standard containers to define those names. Of course, it also works fine with other containers that do the same.