Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Characters::FormatString< CHAR_T > Struct Template Reference

Roughly equivalent to std::wformat_string, except that it can be constructed from 'char' string, and if 'char' require ASCII characters for format string. More...

#include <Format.h>

Public Member Functions

constexpr wstring_view get () const
 
constexpr qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view getx_ () const
 

Detailed Description

template<typename CHAR_T>
struct Stroika::Foundation::Characters::FormatString< CHAR_T >

Roughly equivalent to std::wformat_string, except that it can be constructed from 'char' string, and if 'char' require ASCII characters for format string.

Note
- the lifetime of the string argument to FormatString is application-lifetime - because the string is typically saved by reference. This is meant to be used with "foo={}"_f syntax - with constant c strings.

Sadly, I know of no way to check the lifetime of the argument, so this goes un-enforced.

Note
Types that can be formatted with FormatString (are formattable with it) are: Anything that is std::formattable<T,wchar_t> (see https://en.cppreference.com/w/cpp/utility/format/formatter) in particular: o any class with .ToString() method o std::type_index o std::is_enum<> o std::exception o std::filesystem::path o exception_ptr o POD types (int, bool, double, etc) o String, or any T IConvertibleToString<T> (such as std::wstring) o container (T) where T is a IToString (something you can call Characters::ToStirng() on), such as o is_array<T> o anything with .begin (), .end () - so any container/iterable o std::pair<T1,T2> o std::tuple<TN...> o std::optional<T> o KeyValuePair<T1,T2> o CountedValue<T> o atomic<T> o std::variant<TN....>
Example Usage
String a = FormatString<char>{"Internet Media Type {} not supported"sv}(mediaType);
String sameAsA = "Internet Media Type {} not supported"_f (mediaType);
DbgTrace ("prettyVersionString={}"_f, ppv);
DbgTrace ("currentException={}"_f, current_exception ());
DbgTrace ("seq={}"_f, Sequence<IO::Networking::URI>{...});
#define DbgTrace
Definition Trace.h:309
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Roughly equivalent to std::wformat_string, except that it can be constructed from 'char' string,...

Definition at line 65 of file Characters/Format.h.

Member Function Documentation

◆ get()

template<typename CHAR_T >
constexpr wstring_view Stroika::Foundation::Characters::FormatString< CHAR_T >::get ( ) const
constexpr

This retrieves the underlying string data - for the format string itself (regardless of how created, as a wstring_view).

Definition at line 18 of file Characters/Format.inl.

◆ getx_()

template<typename CHAR_T >
constexpr qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view Stroika::Foundation::Characters::FormatString< CHAR_T >::getx_ ( ) const
constexpr

Hack for interfacing with fmtlib - dont use unless you need to interact directly with fmtlib

Definition at line 23 of file Characters/Format.inl.


The documentation for this struct was generated from the following files: