forwards.h 725 B

123456789101112131415161718192021222324
  1. //
  2. // forwards.h
  3. // string-utils
  4. //
  5. // Created by Sam Jaffe on 6/12/22.
  6. // Copyright © 2022 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include "string_utils/traits.h"
  10. namespace string_utils {
  11. // A helper object for providing partial specializations for casting
  12. template <typename, typename = void> struct cast_helper;
  13. // The main parser
  14. template <typename T> std::pair<T, bool> cast(std::string_view str) noexcept;
  15. template <typename T, typename S> std::pair<T, bool> cast(std::vector<S> const &str) noexcept;
  16. template <typename S, typename T,
  17. typename = std::enable_if_t<detail::has_result<cast_helper<T>(S, T&)>{}>>
  18. bool cast(S const &str, T & to) noexcept { return cast_helper<T>{}(str, to); }
  19. }