Spicy
extension-points.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 
8 namespace hilti::rt {
9 
10 // See https://stackoverflow.com/questions/28070519/customization-points-and-adl.
11 namespace detail::adl {
12 struct tag {};
13 
14 #if __GNUC__
15 // TODO(robin): gcc9 doesn't allow to delete these, not sure why. Using
16 // extern instead, without implementation.
17 extern std::string to_string();
18 #else
19 std::string to_string() = delete;
20 #endif
21 
22 } // namespace detail::adl
23 
25 template<typename T>
26 std::string to_string(T&& x) {
27  using detail::adl::to_string;
28  return to_string(std::forward<T>(x), detail::adl::tag{});
29 }
30 
31 namespace detail {
32 template<typename T>
33 inline std::string to_string_for_print(const T& x) {
34  return hilti::rt::to_string(x);
35 }
36 } // namespace detail
37 
44 template<typename T>
45 inline std::string to_string_for_print(const T& x) {
46  return detail::to_string_for_print(x);
47 }
48 
49 } // namespace hilti::rt
std::string to_string(T &&x)
Definition: extension-points.h:26
Definition: any.h:7
Definition: extension-points.h:12