Я сразу же сделал небольшую тестовую программу, чтобы попробовать это, но у меня всегда возникали ошибка компонента, как я ожидал. В этом, если пользовательский тип имеет публичное начало и end методы, библиотека отформатирует последовательность как разделенный запятой список, заключенный в квадратные скобки. (Или что-то еще?) < /P>
Вот автономная резо: < /p>
Код: Выделить всё
#include
#include
class MyType {
public:
MyType() : m_values{1, 2, 3, 4} {}
using internal_type = std::array;
using const_iterator = typename internal_type::const_iterator;
const_iterator cbegin() const { return m_values.cbegin(); }
const_iterator cend() const { return m_values.cend(); }
const_iterator begin() const { return cbegin(); }
const_iterator end() const { return cend(); }
private:
internal_type m_values;
};
int main() {
MyType foo;
// Since MyType is a user-defined type, I would not
// expect this print statement to compile without a
// specialization of std::formatter, but because
// it's iterable, it prints: "foo = [1, 2, 3, 4]\n".
std::print("foo = {}\n", foo);
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... s-iterable