PrevUpHomeNext

esv::str_new


Life is anti-fragile.

esv::str_new

esv::str_new is an alias template or a "derived from" class, used to create a string by new, by guaranteeing always auto-fill '\0' for empty space.

Cannibalism is forbidden by nature.

esv::str_new_class

It is alias template of or derived from esv::str_new_class, for support specific character type.

The preferred choice is to use alias template, but for compatible, "derived from" is selected.

Rules:

c++ example

#include <esvcpp/core.hpp>

int main()
{
	// Allocate 17+1 size space, and init them with '\0'
	// const char * works for return type.
	const char * s1 = esv::str_new<17>{};

	// Allocate esv::str_size("Hell c++!")+1 size space,
	// and init them with "Hell c++!", the rest with '\0'
	// char * works for return type too.
	char * s2 = esv::str_new{"Hell c++!"};

	// Allocate 17+1 size space,
	// init first esv::str_size("Hell c++!") size space with "Hell c++!",
	// and init the rest space with '\0'.
	const char * s3 = esv::str_new<17>{"Hell c++!"};

	// Allocate 4+1 size space,
	// init first 4 size space with "Hell",
	// and init the rest space with '\0'.
	const char * s4 = esv::str_new<4>{"Hell c++!"};

	esv::print(s1, s2, s3, s4);

	// All of string created by esv::str_new must be destroyed by delete .

	delete [] s1;
	delete [] s2;
	delete [] s3;
	delete [] s4;
}

See Also

esv::wstr_new

esv::u8str_new

esv::u16str_new

esv::u32str_new

esv::print

esv::str_size


PrevUpHomeNext

esv::print