我可以测试wstring::迭代器是否与非特定的::end相等吗?



我希望重载操作符[]。我希望接受std::wstring::迭代器作为这个方法的参数。但是,我希望对这个迭代器进行自增,直到到达wstring的末尾。有办法做到这一点吗?下面是一些伪代码,希望能让我的观点更清楚:

MyClass operator[](std::wstring::iterator it)
{
    /* Obviously this wstring::iterator::parent method is a figment
     * of my imagination; but hopefully it'll give the reader some
     * idea what I wish to achieve. */
    while (++it != it.parent_wstring.end())
        { party(); }
}

我尝试与类型强制转换的nullptr进行如下比较:

if (it == (std::wstring::iterator)nullptr)
    { party(); }

有了这个奇妙的想法:

if (it == std::wstring(L"").end())
    { party(); }

但都不起作用。如果以上任何一种努力导致了你的尴尬,请向我道歉(以及一些愉快的虐待)。

明白了。有几分.

if (*it == 0)
        { party(); }

这让我得到了我想要的派对。请鼓励任何其他答案(这可能是比本质上解引用end迭代器更好的主意)!我要去看看我能在多大程度上依赖于0

最新更新