utx::print is the object of template print class utx::print_class to print many different values without worrying about their types. It is used to output any printable information to char based standard stream, aka std::cout, std::wcout, etc. However the ouput stream can be changed. utx::print is the main print utility of utxcpp. It can print many different types of values by one call. utx::print has a variadic template member function to do the printing, by one call, it is pre-defined format printer, every items are splitted by a space, std::endl or '\n' character will be added at the end. Almost every printable value can be printed by utx::print, and other values can be printed by utx::print after overloading operator<<. utx::print is the most important api of utxcpp.
utx::print has been updated.
utx::print or utx::print_class has been updated since Nov. 17, 2023. From now on, utx::print and old print-all have been merged to one utx::print, that means utx::print can not only print many different types of single printable values, but also can print many different types of printable containers, ranges, and tuples.
In addition, utx::print can print nested ranges, tuples, ranges of tuples, and or tuples of ranges.
utx::print_class is a template class
template <utx::chara char_xt> requires utx::same_as<utx::remove_cvref_t<char_xt>, char_xt> class print_class;
The utx::chara concept requires the type char_xt must be one of char, char8_t, char16_t, char32_t, wchar_t.
The "requires" concept constrains that the type char_xt must not have const and reference.
So char or wchar_t is accepted by utx::print_class template, but const char, char &, or const char &, etc. are not accepted by utx::print_class template.
Currently, only char and wchar_t are implemented by c++ standard ostream, so char8_t, char16_t, char32_t are not available for utx::print_class now.
utx::print_class is inheritence and polymorphism friendly. It has virtual destructor. Its member data or member functions are protected or public.
A constructor must at least set to initialize __sout to attach an external ostream, such as std::cout, or std::wcout.
4x2 constructors
//////////////////////////////////////////////////////////////////////////////// // These two constructors init to attach external ostream print_class(ostream_type & __external_ostream__); print_class(ofstream_type & __external_ofstream__); //////////////////////////////////////////////////////////////////////////////// // These two constructors init to attach external ostream, // and init the three delimiters. print_class( ostream_type & __external_ostream__, const utx::delim_base<string_type> & __init_nested_range_delim__, const utx::delim_base<string_type> & __init_range_delim__, const utx::delim_base<string_type> & __init_value_delim__ ); print_class( ofstream_type & __external_ofstream__, const utx::delim_base<string_type> & __init_nested_range_delim__, const utx::delim_base<string_type> & __init_range_delim__, const utx::delim_base<string_type> & __init_value_delim__ ); //////////////////////////////////////////////////////////////////////////////// // These two constructors init to attach external ostream, // and init if it prints \n at the end, // and if it aligns left for next line printed. print_class( ostream_type & __external_ostream__, utx::mb __newline__, utx::mb __align_left__ ); print_class( ofstream_type & __external_ofstream__, utx::mb __newline__, utx::mb __align_left__ ); //////////////////////////////////////////////////////////////////////////////// // These two constructors init what all above constructors can init. print_class( ostream_type & __external_ostream__, const utx::delim_base<string_type> & __init_nested_range_delim__, const utx::delim_base<string_type> & __init_range_delim__, const utx::delim_base<string_type> & __init_value_delim__, utx::mb __newline__, utx::mb __align_left__ ); print_class( ofstream_type & __external_ofstream__, const utx::delim_base<string_type> & __init_nested_range_delim__, const utx::delim_base<string_type> & __init_range_delim__, const utx::delim_base<string_type> & __init_value_delim__, utx::mb __newline__, utx::mb __align_left__ );
Every call of utx::print, utx::wprint, etc., the std::boolalpha, std::fixed, and std::setprecision(10) will be set. The user-defined flags can change them, but keep in the current call session, and will be lost after ending current print call, never existed in next print call. No matter how many times of calling utx::print, utx::wprint, etc., and no matter how the user set fmt-flags to utx::print, utx::wprint, etc., the standard output std::cout, std::cerr, std::wcout etc. will be not affected.
#include <utxcpp/core.hpp>
![]() |
Note |
---|---|
|
#include <utxcpp/core.hpp> int main() { utx::print(true, ':', 3.14, "kg", "waters"); }
c++ project: Utxcpp utx::print