strconv.h 776 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // stringizer.h
  3. // serializer
  4. //
  5. // Created by Sam Jaffe on 3/15/23.
  6. //
  7. #pragma once
  8. #include <string>
  9. #include <string_view>
  10. #include <type_traits>
  11. #include <magic_enum.hpp>
  12. #include <serializer/traits.h>
  13. namespace serializer {
  14. using ::std::to_string;
  15. inline std::string to_string(char const *str) { return str; }
  16. inline std::string to_string(std::string const &str) { return str; }
  17. inline std::string to_string(std::string_view str) { return std::string(str); }
  18. template <typename T> std::string to_string(T const * t) { return to_string(*t); }
  19. template <typename T> std::string to_string(T const &elem) {
  20. if constexpr (std::is_enum_v<T>) {
  21. return std::string(magic_enum::enum_name(value));
  22. } else {
  23. static_assert(detail::always_false<T>{});
  24. }
  25. }
  26. }