Spicy
result.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 
7 #include <hilti/rt/extension-points.h>
8 #include <hilti/rt/result.h>
9 #include <hilti/rt/types/error.h>
10 #include <hilti/rt/util.h>
11 
12 namespace hilti::rt {
13 
14 namespace detail::adl {
15 template<typename T>
16 inline std::string to_string(Result<T> x, adl::tag /*unused*/) {
17  return x ? hilti::rt::to_string(*x) : hilti::rt::to_string(x.error());
18 }
19 
20 template<typename T>
21 inline std::string to_string_for_print(Result<T> x, adl::tag /*unused*/) {
22  return x ? hilti::rt::to_string_for_print(*x) : hilti::rt::to_string(x.error());
23 }
24 
25 } // namespace detail::adl
26 
27 template<>
28 inline std::string detail::to_string_for_print<Result<std::string>>(const Result<std::string>& x) {
29  return x ? *x : hilti::rt::to_string(x.error());
30 }
31 
32 template<>
33 inline std::string detail::to_string_for_print<Result<std::string_view>>(const Result<std::string_view>& x) {
34  return x ? std::string(*x) : hilti::rt::to_string(x.error());
35 }
36 
37 } // namespace hilti::rt
std::string to_string(T &&x)
Definition: extension-points.h:26
std::string to_string_for_print(const T &x)
Definition: extension-points.h:45
Definition: any.h:7