LeviLamina
Loading...
Searching...
No Matches
Serializer.h
1#pragma once
2#include "ll/api/reflection/ReflectionError.h"
3#include "ll/api/utils/StringUtils.h"
4#include <type_traits>
5
6namespace ll::reflection {
7
8template <typename T, typename J = void>
9struct Serializer {};
10
11template <>
12struct Serializer<bool> {
13 static std::string to_string(bool t) { return t ? "true" : "false"; }
14 static ll::Expected<bool> from_string(std::string_view s) { return ll::string_utils::svtobool(s); }
15};
16
17template <typename T>
18 requires(std::is_arithmetic_v<T> && !std::is_same_v<T, bool> && !traits::is_char_v<T>)
20 static std::string to_string(T t) { return fmt::to_string(t); }
21 static ll::Expected<T> from_string(std::string_view s) { return ll::string_utils::svtonum<T>(s); }
22};
23
24} // namespace ll::reflection
Definition Serializer.h:9