gz-cpp-util 1.3
A c++20 library containing various utilities
to_string.hpp File Reference

Contains functions to convert types to string. More...

#include "../concepts.hpp"
#include <string>
#include <string_view>
#include <ranges>

Go to the source code of this file.

Concepts

concept  gz::util::Stringy
 same as std::string, std::string_view or const char*
 
concept  gz::util::CanConstructString
 can construct std::string from T
 
concept  gz::util::HasToStringMember
 has .toString() const member
 
concept  gz::util::HasToStringMember2
 has .to_string() const member
 
concept  gz::util::WorksWithStdToString
 works with std::to_string()
 
concept  gz::util::ConvertibleToStringGlobal
 toString function overload exists in global namespace and returns std::string
 
concept  gz::util::Vector2ConvertibleToString
 Type having string-convertible x, y members and sizeof(T) == 2 * sizeof(x)
 
concept  gz::util::Vector3ConvertibleToString
 Type having string-convertible x, y, z members and sizeof(T) == 3 * sizeof(x)
 
concept  gz::util::Vector4ConvertibleToString
 Type having string-convertible x, y, z, w members and sizeof(T) == 4 * sizeof(x)
 
concept  gz::util::Extent2DConvertibleToString
 Type having string-convertible width, height members and sizeof(T) == 2 * sizeof(width)
 
concept  gz::util::Extent3DConvertibleToString
 Type having string-convertible width, height, depth members and sizeof(T) == 3 * sizeof(width)
 
concept  gz::util::_ConvertibleToString
 Everything that is convertible to string with toString at this point.
 
concept  gz::util::ForwardRangeConvertibleToString
 Forward range having string-convertible elements.
 
concept  gz::util::PairConvertibleToString
 Pair having string-convertible elements.
 
concept  gz::util::MapConvertibleToString
 Container having string-convertible pairs.
 
concept  gz::ConvertibleToString
 Any type where gz::toString(t) exists.
 

Functions

template<gz::util::False T>
std::string toString (const T &s)
 Declaration of toString in global namespace, so that concepts can use it.
 
1) Converting a type to string

All toString functions for types that satisfy util::ToStringBasicNoPtr or util::PtrToToStringBasicType

template<util::Stringy T>
std::string gz::toString (const T &t)
 Return the string. More...
 

Detailed Description

Contains functions to convert types to string.

Function Documentation

◆ toString()

template<util::Stringy T>
std::string gz::toString ( const T &  t)
inline

Return the string.

Construct a string from a forward range holding a pair, eg a map.

Construct a string from a pair.

Construct a string from a forward range.

Construct a string from the element the pointer points at.

Construct a string from a type having width and height members.

Construct a string from a vector with x, y, z, w members.

Construct a string from a vector with x, y members.

Construct a string from a type that has toString declared in global namespace.

Construct a string from a boolean.

Construct a string from a number.

Construct a string from a type having a to_string() const member function.

Construct a string from a type having a toString() const member function.

Construct a string from a string like-type.

Returns
static_cast<std::string>(t)
std::string(t)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
t.toString()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
t.to_string()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
std::to_string(t)

Unlike std::to_string(bool), which returns 0 or 1, this function returns "true" or "false"

Returns
"true" or "false"

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( x, y )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( x, y, z )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( x, y, z, w )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( width, height )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( width, height, depth )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
*t

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
[ x1, x2, ... ]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
( first, second )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
{ first: second, first: second, ... }