ProjectLoader: replace access to listific with iterator; minor fixes

This commit is contained in:
Michael Ehrenreich
2023-02-27 02:21:37 +01:00
parent 3fd8b9e674
commit 38203d1653
2 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,10 @@
#include <concepts>
#include <list>
#include <type_traits> #include <type_traits>
#include <vector>
#include <QJsonArray>
#include <QJsonObject>
#include "projectloader.h" #include "projectloader.h"
@ -299,9 +305,9 @@ template <detail::Listific T>
std::expected<QJsonArray, QString> save(const T &val) { std::expected<QJsonArray, QString> save(const T &val) {
QJsonArray arr; QJsonArray arr;
for (size_t i = 0; i < val.size(); i++) { size_t i = 0;
const auto &el = val[i]; for (auto it = std::cbegin(val); it != std::cend(val); it++, i++) {
auto json = save<typename T::value_type>(el); auto json = save<typename T::value_type>(*it);
if (json) { if (json) {
arr.push_back(json.value()); arr.push_back(json.value());
} else { } else {

View File

@ -2,16 +2,12 @@
#define PROJECTLOADER_H #define PROJECTLOADER_H
#include <expected> #include <expected>
#include <vector>
#include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QString>
#include "lightproject.h" #include "lightproject.h"
#include "projectloader.h"
namespace ProjectLoader { namespace ProjectLoader {
std::expected<LightProject, QString> loadProject(const QJsonDocument &json); std::expected<LightProject, QString> loadProject(const QJsonDocument &json);