0

I'm trying to under the parse function for creating a formatter for a custom type in fmt. In their documentation (https://fmt.dev/dev/api.html) there is this line that has some sort of loop construct I haven't seen before:

auto it = ctx.begin(), end = ctx.end();
if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++;

It's obviously a loop using iterators, presumably something new in C++17. What is it? Full example here: https://godbolt.org/z/fEGvaj

4

1 回答 1

0

formatter::parse函数采用解析上下文ctx并检查范围是否[ctx.begin(), ctx.end())包含格式说明符fe在此示例中。

if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++;
    ^                 ^             ^
 check if the         check if the first
 range is empty       character is 'f' or 'e'

这里没有什么特别新奇的,这段代码兼容C++98。

于 2021-01-22T01:45:12.180 回答