3#include "../concepts.hpp"
9#define GZ_UTIL_STRING_CONCEPTS
14template<gz::util::False T>
32 requires(
const T& t) {
33 { std::string(t) } -> std::same_as<std::string>;
41 requires(
const T& t) { { t.toString() }->
Stringy; };
49 requires(
const T& t) { { t.to_string() }->
Stringy; };
58 requires(
const T& t) { { std::to_string(t) } ->
Stringy; };
68 requires(
const T& t) {
69 {
::toString(t) } -> std::same_as<std::string>;
73 concept _ToStringBasicNoPtr =
81#ifndef GZ_TO_STRING_NO_VECTORS
87 { t.x } -> _ToStringBasicNoPtr;
88 { t.y } -> _ToStringBasicNoPtr;
89 requires sizeof(t.x) * 2 ==
sizeof(T);
95 { t.x } -> _ToStringBasicNoPtr;
96 { t.y } -> _ToStringBasicNoPtr;
97 { t.z } -> _ToStringBasicNoPtr;
98 requires sizeof(t.x) * 3 ==
sizeof(T);
104 { t.x } -> _ToStringBasicNoPtr;
105 { t.y } -> _ToStringBasicNoPtr;
106 { t.z } -> _ToStringBasicNoPtr;
107 { t.w } -> _ToStringBasicNoPtr;
108 requires sizeof(t.x) * 4 ==
sizeof(T);
115 { t.width } -> _ToStringBasicNoPtr;
116 { t.height } -> _ToStringBasicNoPtr;
117 requires sizeof(t.width) * 2 ==
sizeof(T);
123 { t.width } -> _ToStringBasicNoPtr;
124 { t.height } -> _ToStringBasicNoPtr;
125 { t.depth } -> _ToStringBasicNoPtr;
126 requires sizeof(t.width) * 3 ==
sizeof(T);
131 concept _ToStringBasicOrVectorNoPtr =
132 _ToStringBasicNoPtr<T>
133#ifndef GZ_TO_STRING_NO_VECTORS
143 concept PtrToToStringBasicOrVector =
144 !_ToStringBasicOrVectorNoPtr<T> &&
145 _ToStringBasicOrVectorNoPtr<std::remove_pointer_t<T>>;
161 template<util::Stringy T>
163 return static_cast<std::string
>(t);
170 template<util::CanConstructString T>
171 inline std::string
toString(
const T& t) {
172 return std::string(t);
180 template<util::HasToStringMember T>
181 inline std::string
toString(
const T& t) {
190 template<util::HasToStringMember2 T>
191 inline std::string
toString(
const T& t) {
192 return t.to_string();
200 template<util::WorksWithStdToString T>
201 inline std::string
toString(
const T& t) {
202 return std::to_string(t);
211 template<std::same_as<
bool> T>
212 inline std::string
toString(
const T& b) {
213 return b ?
"true" :
"false";
220 template<util::ConvertibleToStringGlobal T>
221 inline std::string
toString(
const T& t) {
225#ifndef GZ_TO_STRING_NO_VECTORS
231 template<util::Vector2ConvertibleToString T>
232 inline std::string
toString(
const T& t) {
233 std::string s =
"( ";
244 template<util::Vector3ConvertibleToString T>
245 inline std::string
toString(
const T& t) {
246 std::string s =
"( ";
258 template<util::Vector4ConvertibleToString T>
259 inline std::string
toString(
const T& t) {
260 std::string s =
"( ";
273 template<util::Extent2DConvertibleToString T>
274 inline std::string
toString(
const T& t) {
275 std::string s =
"( ";
286 template<util::Extent3DConvertibleToString T>
287 inline std::string
toString(
const T& t) {
288 std::string s =
"( ";
301 template<util::PtrToToStringBasicOrVector T>
302 inline std::string
toString(
const T& t) {
317 requires (
const T& t) {
333 requires _TypeOrForwardRangeConvertibleToString<
decltype(p.first)>;
334 requires _TypeOrForwardRangeConvertibleToString<
decltype(p.second)>;
362 template<util::ForwardRangeConvertibleToString T>
364 std::string s =
"[ ";
365 for (
auto it = t.begin(); it != t.end(); it++) {
369 s.erase(s.size() - 2);
380 template<util::PairConvertibleToString T>
381 inline std::string
toString(
const T& t) {
390 template<util::MapConvertibleToString T>
392 std::string s =
"{ ";
393 for (
const auto& [k, v] : t) {
398 s.erase(s.size() - 2);
410 requires (
const T& t) {
Any type where gz::toString(t) exists.
Definition: to_string.hpp:409
can construct std::string from T
Definition: to_string.hpp:30
toString function overload exists in global namespace and returns std::string
Definition: to_string.hpp:62
Type having string-convertible width, height members and sizeof(T) == 2 * sizeof(width)
Definition: to_string.hpp:113
Type having string-convertible width, height, depth members and sizeof(T) == 3 * sizeof(width)
Definition: to_string.hpp:121
Forward range having string-convertible elements.
Definition: to_string.hpp:325
has .to_string() const member
Definition: to_string.hpp:45
has .toString() const member
Definition: to_string.hpp:38
Satisfied when T is in PackTypes.
Definition: concepts.hpp:9
Container having string-convertible pairs.
Definition: to_string.hpp:339
Pair having string-convertible elements.
Definition: to_string.hpp:332
same as std::string, std::string_view or const char*
Definition: to_string.hpp:26
Type having string-convertible x, y members and sizeof(T) == 2 * sizeof(x)
Definition: to_string.hpp:85
Type having string-convertible x, y, z members and sizeof(T) == 3 * sizeof(x)
Definition: to_string.hpp:93
Type having string-convertible x, y, z, w members and sizeof(T) == 4 * sizeof(x)
Definition: to_string.hpp:102
works with std::to_string()
Definition: to_string.hpp:53
Everything that is convertible to string with toString at this point.
Definition: to_string.hpp:316
std::string toString(const T &s)
Declaration of toString in global namespace, so that concepts can use it.