12 #ifndef DOCWIRE_CONVERT_BASE_H
13 #define DOCWIRE_CONVERT_BASE_H
17 #include "error_tags.h"
18 #include "make_error.h"
19 #include "source_location.h"
20 #include "type_name.h"
34 template <
typename To,
typename From>
35 concept conversion_implementation_exists =
requires(
const From& from) {
44 template<
typename To,
typename From>
45 requires conversion_implementation_exists<To, From>
46 constexpr std::optional<To> operator()(
const From& from)
const noexcept
63 template<
typename To,
typename From>
64 requires conversion_implementation_exists<To, From>
65 constexpr std::optional<To>
try_to(
const From& from) noexcept
77 template<
typename To,
typename From>
78 requires conversion_implementation_exists<To, From>
79 To
to(
const From& from)
81 auto result = try_to<To>(from);
82 if (!result.has_value())
84 auto context = std::make_tuple(
"Failed to convert value",
"from_type"_v = type_name::pretty<From>(),
"to_type"_v = type_name::pretty<To>(),
errors::uninterpretable_data{});
Namespace for type conversion utilities.
requires constexpr conversion_implementation_exists< To, From > std::optional< To > try_to(const From &from) noexcept
Tries to convert a value of type From to type To.
requires conversion_implementation_exists< To, From > To to(const From &from)
Converts a value of type From to type To.
DOCWIRE_CORE_EXPORT std::optional< std::chrono::sys_seconds > convert_impl(with::date_format::iso8601 s, dest_type_tag< std::chrono::sys_seconds >) noexcept
Converts an ISO 8601 date string to sys_seconds.
auto make_error_from_tuple(const source_location &location, std::tuple< Context... > &&context_tuple)
Creates an error object from a tuple of context information.
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.
A tag type used for dispatching convert_impl overloads based on the destination type.
Uninterpretable data error tag.