xtd 0.2.0
Loading...
Searching...
No Matches
xtd::stringable< value_t > Struct Template Reference

Definition

template<class value_t>
struct xtd::stringable< value_t >

Represents the stringable concept.

Definition
template<class value_t>
Definition stringable.hpp:22
Header
#include <xtd/stringable>
Namespace
xtd
Library
xtd.core
Returns
true if value_t is derived from xtd::object, or value_t is derived from xtd::istringable, or value_t is derived from xtd::iformatable, or value_t is derived from std::exception, or value_t is an enum, value_t is std::ranges::range, or value_t has output stream operator <<; otherwise false.
Remarks
If a type has only a xtd::to_string specialisation, it is always considered not stringable.
Examples
The following code shows how to use xtd::stringable concept
#include <xtd/xtd>
struct my_formatable_string : public iformatable {
my_formatable_string(const string& value) : value {value} {}
auto to_string(const string& format, const globalization::culture_info& culture) const noexcept -> string override {return value;}
string value;
};
struct my_stringable_string : public istringable<my_stringable_string> {
my_stringable_string(const string& value) : value {value} {}
auto to_string() const noexcept -> string override {return value;}
string value;
};
struct my_streamable_string {
friend auto operator <<(std::ostream& os, const my_streamable_string& value) noexcept -> std::ostream& {return os << value.value;}
string value;
};
struct my_object_string : public object {
my_object_string(const string& value) : value {value} {}
auto to_string() const noexcept -> string override {return value;}
string value;
};
struct my_to_string_string {
string value;
};
template<>
auto xtd::to_string(const my_to_string_string& value, const string& format, const std::locale& loc) -> string {
return value.value;
}
struct my_string {
string value;
};
auto log_to_console(const stringable auto& value) noexcept {
console::write_line(value);
}
auto main() -> int {
log_to_console(my_formatable_string {"my_formatable_string"});
log_to_console(my_stringable_string {"my_stringable_string"});
log_to_console(my_streamable_string {"my_streamable_string"});
log_to_console(my_object_string {"my_object_string"});
//log_to_console(my_to_string_string {"my_to_string_string"}); // Does not build
//log_to_console(my_string {"my_string"}); // Does not build
log_to_console(date_time::now());
log_to_console(environment::version());
log_to_console(day_of_week::saturday);
log_to_console(42);
log_to_console(std::vector {1, 2, 3, 4, 5});
log_to_console(array {1, 2, 3, 4, 5}.select(delegate_(auto v) {return v * v;}));
log_to_console(array {1, 2, 3, 4, 5} | std::views::transform(delegate_(auto v) {return v * v * v;}));
log_to_console(argument_out_of_range_exception {});
}
// This code can produce the following output :
//
// my_formatable_string
// my_stringable_string
// my_streamable_string
// my_object_string
// 1/11/2026 6:33:25 PM
// 0.2.0
// saturday
// 42
// [1, 2, 3, 4, 5]
// [1, 4, 9, 16, 25]
// [1, 8, 27, 64, 125]
// xtd::argument_out_of_range_exception : Specified argument is out of range of valid values.
// at xtd::argument_out_of_range_exception::argument_out_of_range_exception(xtd::diagnostics::stack_frame const&) in argument_out_of_range_exception.hpp:line 30
// at main in stringable.cpp:line 62
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:43
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:42
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:932
@ v
The V key.
Definition console_key.hpp:130
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375

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