draconisplusplus/include/rfl/json/save.hpp
2024-06-16 00:13:15 -04:00

29 lines
646 B
C++

#ifndef RFL_JSON_SAVE_HPP_
#define RFL_JSON_SAVE_HPP_
#include <fstream>
#include <iostream>
#include <string>
#include <yyjson.h>
#include "../Result.hpp"
#include "../io/save_string.hpp"
#include "write.hpp"
namespace rfl {
namespace json {
template <class... Ps>
Result<Nothing>
save(const std::string& _fname, const auto& _obj, const yyjson_write_flag _flag = 0) {
const auto write_func = [_flag](const auto& _obj, auto& _stream) -> auto& {
return write<Ps...>(_obj, _stream, _flag);
};
return rfl::io::save_string(_fname, _obj, write_func);
}
} // namespace json
} // namespace rfl
#endif