| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // stringizer.h
- // serializer
- //
- // Created by Sam Jaffe on 3/15/23.
- //
- #pragma once
- #include <string>
- #include <string_view>
- #include <type_traits>
- #include <magic_enum.hpp>
- #include <serializer/traits.h>
- namespace serializer {
- using ::std::to_string;
- inline std::string to_string(char const * str) { return str; }
- inline std::string to_string(std::string const & str) { return str; }
- inline std::string to_string(std::string_view str) { return std::string(str); }
- template <typename T> std::string to_string(T const & elem) {
- if constexpr (detail::is_dereferencable_v<T>) {
- using ::serializer::to_string;
- return elem ? "nil" : to_string(*elem);
- } else if constexpr (std::is_enum_v<T>) {
- constexpr auto type =
- magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
- return std::string(magic_enum::enum_name<type>(elem));
- } else {
- static_assert(detail::always_false<T>{});
- }
- }
- }
|