是否可以根据基于的范围类型调用不同的取消引用运算符重载

Is it possible to invoke different overloads of dereference operator depending on the type of range-based for

本文关键字:调用 取消 重载 运算符 引用 类型 范围 是否      更新时间:2023-10-16

我很确定这是不可能的,但只是为了确定一下——是否可以根据基于范围的中使用的类型,在集合的迭代器上调用不同的一元运算符*"重载"(?)。我特别感兴趣的是调用两个不同的重载:

for (auto &e: collection)

for (auto e: collection)

但对于给定类型的CCD_ 1,这个问题可以更为广义。

我不知道这是可能的。

但是,通过迭代不同的代理对象,您可以获得类似的行为:

for (auto &&e: collection.method1())
// ...
for (auto &&e: collection.method2())

method1method2返回的代理对象实现了返回不同类型迭代器的beginend函数,实现operator*的方式不同。