xtd 0.2.0
format_optional.cpp

Show how to use format xtd::format class with std::optional.

#include <xtd/console>
#include <xtd/environment>
#include <xtd/format>
#include <xtd/null_opt>
#include <xtd/optional>
using namespace xtd;
auto main() -> int {
console::out << format("{}", optional<string> {"string value"}.value()) << environment::new_line;
console::out << format("{}", optional<string> {}.value_or("fallback string")) << environment::new_line;
}
// This code produces the following output :
//
// (string value)
// string value
// fallback string
// (null)
// (null)
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition console.hpp:52
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
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:20
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:25
constexpr null_opt nullopt
Represents a nullopt value. Used to indicate that an std::optional does not contain a value.
Definition nullopt.hpp:26
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8