PrevUpHomeNext

esv::print


esv::print - esv::print_class

esv::print

esv::print is a multi-value printer for c++. It is an easy, simple and versatile multi-value printer. esv::print prints as many value types as possible. It can print many single values, many c++ tuples, many c++ containers, many c++ nested containers, and many values that are mixed from above types at the same time.

esv::print

+ Print single value:

esv::print prints a single c++ value, the value can be c++ integral, floating point, character, string, or a value that has overloaded operator<< .

+ Print single container:

esv::print prints a single c++ container, the container can be a printable standard c++ container, or an user-defined printable c++ container.

+ Print single nested container:

esv::print prints a nested c++ container, the container can be a nested standard c++ container, or an user-defined nested c++ container, the basic value of the container must be printable.

+ Print single tuple:

esv::print prints a single tuple, every element of the tuple must be printable.

+ Print many values:

esv::print prints many single values, many single containers, many single nested containers, many single tuples, and many mixed values of above types.

esv::print

esv::print is the object of template print class esv::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. esv::print is the main print utility of esvcpp. It can print many different types of values by one calling. esv::print has a variadic template member function to do the printing, by one calling, it is pre-defined format printer, every items are splitted by a space. std::endl or '\n' character will be added in the end. Almost every printable value can be printed by esv::print, and other values can be printed by esv::print after overloading operator<<. esv::print is the most important api of esvcpp.

esv::print has been updated.

esv::print or esv::print_class has been updated since Nov. 17, 2023. From now on, esv::print and old print-all have been merged to one api: esv::print, that means esv::print can not only print many different types of single printable values, but also print many different types of printable containers, ranges, and tuples.

In addition, esv::print can print nested ranges, tuples, ranges of tuples, and or tuples of ranges.

Everyone shows ecological charm everywhere.

esv::print_class

esv::print_class is a template class for all esvcpp print api.

template <esv::chara char_xt>
	requires esv::same_as<esv::remove_cvref_t<char_xt>, char_xt>
class print_class;

The esv::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 esv::print_class template, but const char, char &, or const char &, etc. are not accepted by esv::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 esv::print_class now.

(esv::print)

Polymorphism Friendly

esv::print_class is inheritance and polymorphism friendly. It has virtual destructor. Its member data or member functions are protected or public.

Constructors

esv::print_class constructors

A constructor of esv::print_class must initialize __sout to attach an external ostream, such as std::cout, or std::wcout at least.

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 esv::delim_base<string_type> & __init_nested_range_delim__,
	const esv::delim_base<string_type> & __init_range_delim__,
	const esv::delim_base<string_type> & __init_value_delim__
);
print_class(
	ofstream_type & __external_ofstream__,
	const esv::delim_base<string_type> & __init_nested_range_delim__,
	const esv::delim_base<string_type> & __init_range_delim__,
	const esv::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__,
	esv::mb __newline__,
	esv::mb __align_left__
	);
print_class(
	ofstream_type & __external_ofstream__,
	esv::mb __newline__,
	esv::mb __align_left__
);

////////////////////////////////////////////////////////////////////////////////
// These two constructors init what all above constructors can init.

print_class(
	ostream_type & __external_ostream__,
	const esv::delim_base<string_type> & __init_nested_range_delim__,
	const esv::delim_base<string_type> & __init_range_delim__,
	const esv::delim_base<string_type> & __init_value_delim__,
	esv::mb __newline__,
	esv::mb __align_left__
);
print_class(
	ofstream_type & __external_ofstream__,
	const esv::delim_base<string_type> & __init_nested_range_delim__,
	const esv::delim_base<string_type> & __init_range_delim__,
	const esv::delim_base<string_type> & __init_value_delim__,
	esv::mb __newline__,
	esv::mb __align_left__
);

Public Member Functions

List public member functions of esv::print_class. The protected members are nost listed here.

Lock and Mutex Support

esv::print_class object such as esv::print does not include any threading and mutex header, however, you can pass a mutex to esv::print, that mutex will be constrained and matched by esv::param_mutex, then the mutex will be locked and unlocked inside the esv::print calling stack.

std::mutex mutex;

start_a_thread;
// then use mutex ...
esv::print(mutex, "Hell", "World!");	// mutex will be locked and unlocked inside esv::print .

See esv::param_mutex

std::fmtflags rules

Every calling of esv::print, esv::wprint, etc., the std::boolalpha, std::fixed, and std::setprecision(10) will be set. The user-defined flags can change them, but only be kept in the current calling session, and will be lost after ending current print calling, never existed in next print calling. No matter how many times of calling esv::print, esv::wprint, etc., and no matter how the user set fmt-flags to esv::print, esv::wprint, etc., the standard output std::cout, std::cerr, std::wcout etc. will be not affected.

Public Header

#include <esvcpp/core.hpp>

Notice

[Note] Note
  • It prints a newline character at the end, but can be changed with .set_newline member function.
  • It separates each single value by a space, each range or tuple by \n, each two-dim range or tuple by \n\n, but can be changed by .set_delim member function.
  • It can print nested ranges and nested tuples, nested ranges of tuples, and nested tuples of ranges.
  • concept requirements:
    • Every single value must satisfy esv::kspt::printable or esv::kspt::printable_adapter<char_type>, char_type is a related char-type, such as char or wchar_t .
    • All single values stored in the range or tuple must satisfy printable too.
    • Basic printable types satisfy esv::kspt::printable .
    • Non-basic types must implement operator<< to satisfy esv::kspt::printable .

c++ Example

#include <esvcpp/core.hpp>

int main()
{
	esv::print(true, ':', 3.14, "kg", "waters");
}

See Also

esv::printe

esv::printnl

esv::wprint

esv::wprinte

esv::wprintnl


PrevUpHomeNext

esv::print