#include <xtd/console>
#include <xtd/environment>
#include <xtd/foreground_color>
#include <xtd/iformatable>
class foo1 {
public:
explicit foo1(int value) : value_ {value} {}
string to_string() const noexcept {return string::format("{}", value_);}
string to_string(const string& format, const std::locale& loc) const {return string::format(string::format("{{:{}}}", format), value_);}
private:
int value_ = 0;
};
class foo2 {
public:
explicit foo2(int value) : value_ {value} {}
string to_string() const noexcept {
return string::format(
"{}", value_);}
string to_string(
const string& format,
const std::locale& loc)
const {
return string::format(string::format(
"{{:{}}}", format), value_);}
private:
int value_ = 0;
};
template<>
std::string
xtd::to_string(
const foo2& value,
const std::string& format,
const std::locale& loc) {
return value.to_string(format, loc);}
public:
explicit foo3(int value) : value_ {value} {}
string to_string() const noexcept {
return string::format(
"{}", value_);}
string to_string(
const string& format,
const std::locale& loc)
const override {
return string::format(string::format(
"{{:{}}}", format), value_);}
private:
int value_ = 0;
};
public:
explicit foo4(int value) : value_ {value} {}
string to_string() const noexcept
override {
return string::format(
"{}", value_);}
string to_string(
const string& format,
const std::locale& loc)
const {
return string::format(string::format(
"{{:{}}}", format), value_);}
private:
int value_ = 0;
};
public:
explicit foo5(int value) : value_ {value} {}
string to_string() const noexcept {
return string::format(
"{}", value_);}
string to_string(
const string& format,
const std::locale& loc)
const override {
return string::format(string::format(
"{{:{}}}", format), value_);}
friend std::ostream& operator <<(std::ostream& stream,
const foo5& value) {
return stream << value.to_string(
"", std::locale {});}
private:
int value_ = 0;
};
class foo6 {
public:
explicit foo6(int value) : value_ {value} {}
string to_string(
const string& format,
const std::locale& loc)
const {
return string::format(string::format(
"{{:{}}}", format), value_);}
friend std::ostream& operator <<(std::ostream& stream,
const foo6& value) {
return stream << value.to_string();}
private:
int value_ = 0;
};
template<>
std::string
xtd::to_string(
const foo6& value,
const std::string& format,
const std::locale& loc) {
return value.to_string(format, loc);}
public:
explicit foo7(int value) : value_ {value} {}
using object::to_string;
string to_string(
const string& format,
const std::locale& loc)
const override {
return string::format(string::format(
"{{:{}}}", format), value_);}
private:
int value_ = 0;
};
auto main() -> int {
console::out << "foo1 standard output :" << environment::new_line;
console::out <<
" " <<
f1 << environment::new_line;
console::out <<
" " <<
f1.to_string() << environment::new_line;
try {
console::out << string::format(" {}", f1) << environment::new_line;
console::out <<
" " <<
foreground_color(console_color::red) <<
"exception : " <<
e.message() <<
foreground_color(console_color::default_color) << environment::new_line;
}
try {
console::out << string::format(" 0b{:b8}", f1) << environment::new_line;
console::out <<
" " <<
foreground_color(console_color::red) <<
"exception : " <<
e.message() <<
foreground_color(console_color::default_color) << environment::new_line;
}
console::out <<
" 0b" <<
f1.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo1 write_line :");
console::write(" ");
try {
console::write_line(f1);
}
console::write(" ");
console::write_line(
f1.to_string());
try {
console::write_line(" {}", f1);
console::out <<
" " <<
foreground_color(console_color::red) <<
"exception : " <<
e.message() <<
foreground_color(console_color::default_color) << environment::new_line;
}
try {
console::write_line(" 0b{:b8}", f1);
console::out <<
" " <<
foreground_color(console_color::red) <<
"exception : " <<
e.message() <<
foreground_color(console_color::default_color) << environment::new_line;
}
console::write(" 0b");
console::write_line(
f1.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo2 standard output :" << environment::new_line;
console::out <<
" " <<
f2 << environment::new_line;
console::out <<
" " <<
f2.to_string() << environment::new_line;
console::out << string::format(" {}", f2) << environment::new_line;
console::out << string::format(" 0b{:b8}", f2) << environment::new_line;
console::out <<
" 0b" <<
f2.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo2 write_line :");
console::write(" ");
console::write_line(f2);
console::write(" ");
console::write_line(
f2.to_string());
console::write_line(" {}", f2);
console::write_line(" 0b{:b8}", f2);
console::write(" 0b");
console::write_line(
f2.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo3 standard output :" << environment::new_line;
console::out <<
" " <<
f3 << environment::new_line;
console::out <<
" " <<
f3.to_string() << environment::new_line;
console::out << string::format(" {}", f3) << environment::new_line;
console::out << string::format(" 0b{:b8}", f3) << environment::new_line;
console::out <<
" 0b" <<
f3.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo3 write_line :");
console::write(" ");
console::write_line(f3);
console::write(" ");
console::write_line(
f3.to_string());
console::write_line(" {}", f3);
console::write_line(" 0b{:b8}", f3);
console::write(" 0b");
console::write_line(
f3.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo4 standard output :" << environment::new_line;
console::out <<
" " <<
f4 << environment::new_line;
console::out <<
" " <<
f4.to_string() << environment::new_line;
console::out << string::format(" {}", f4) << environment::new_line;
console::out << string::format(" 0b{:b8}", f4) << environment::new_line;
console::out <<
" 0b" <<
f4.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo4 write_line :");
console::write(" ");
console::write_line(f4);
console::write(" ");
console::write_line(
f4.to_string());
console::write_line(" {}", f4);
console::write_line(" 0b{:b8}", f4);
console::write(" 0b");
console::write_line(
f4.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo5 standard output :" << environment::new_line;
console::out <<
" " <<
f5 << environment::new_line;
console::out <<
" " <<
f5.to_string() << environment::new_line;
console::out << string::format(" {}", f5) << environment::new_line;
console::out << string::format(" 0b{:b8}", f5) << environment::new_line;
console::out <<
" 0b" <<
f5.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo5 write_line :");
console::write(" ");
console::write_line(f5);
console::write(" ");
console::write_line(
f5.to_string());
console::write_line(" {}", f5);
console::write_line(" 0b{:b8}", f5);
console::write(" 0b");
console::write_line(
f5.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo6 standard output :" << environment::new_line;
console::out <<
" " <<
f6 << environment::new_line;
console::out <<
" " <<
f6.to_string() << environment::new_line;
console::out << string::format(" {}", f6) << environment::new_line;
console::out << string::format(" 0b{:b8}", f6) << environment::new_line;
console::out <<
" 0b" <<
f6.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo6 write_line :");
console::write(" ");
console::write_line(f6);
console::write(" ");
console::write_line(
f6.to_string());
console::write_line(" {}", f6);
console::write_line(" 0b{:b8}", f6);
console::write(" 0b");
console::write_line(
f6.to_string(
"b8", std::locale {}));
console::write_line();
console::out << "foo7 standard output :" << environment::new_line;
console::out <<
" " <<
f7 << environment::new_line;
console::out <<
" " <<
f7.to_string() << environment::new_line;
console::out << string::format(" {}", f7) << environment::new_line;
console::out << string::format(" 0b{:b8}", f7) << environment::new_line;
console::out <<
" 0b" <<
f7.to_string(
"b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("foo7 write_line :");
console::write(" ");
console::write_line(f7);
console::write(" ");
console::write_line(
f7.to_string());
console::write_line(" {}", f7);
console::write_line(" 0b{:b8}", f7);
console::write(" 0b");
console::write_line(
f7.to_string(
"b8", std::locale {}));
console::write_line();
}
Represent foreground color output manipulator class.
Definition foreground_color.hpp:20
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ stream
Supports reliable, two-way, connection-based byte streams without the duplication of data and without...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10