Energy is matter.
esv::wstr_new is an alias template or a "derived from" class, used to create a string by new, by guaranteeing always auto-fill L'\0' for empty space.
Cannibalism is forbidden by nature.
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.
new
;
It is designed for the following style usage case originally:
// Can be also applied to esv::wstr_new, ..., etc. char * ptr = esv::str_new<12>{"Hell c++!"}; // 12+1 // The real content of created space is: // "Hell c++!\0\0\0\0" delete [] ptr; // Can be also applied to esv::wstr_new, ..., etc. // Both char * and const char * work, and size in template param can be auto-deduced. const char * ptr2 = esv::str_new{"Hell c++!"}; // 9+1 delete [] ptr2;
#include <esvcpp/core.hpp> int main() { // Allocate 17+1 size space, and init them with L'\0' // const wchar_t * works for return type. const wchar_t * s1 = esv::wstr_new<17>{}; // Allocate esv::wstr_size(L"Hell c++!")+1 size space, // and init them with L"Hell c++!", the rest with L'\0' // wchar_t * works for return type too. wchar_t * s2 = esv::wstr_new{L"Hell c++!"}; // Allocate 17+1 size space, // init first esv::wstr_size(L"Hell c++!") size space with L"Hell c++!", // and init the rest space with L'\0'. const wchar_t * s3 = esv::wstr_new<17>{L"Hell c++!"}; // Allocate 4+1 size space, // init first 4 size space with L"Hell", // and init the rest space with L'\0'. const wchar_t * s4 = esv::wstr_new<4>{L"Hell c++!"}; esv::wprint(s1, s2, s3, s4); // All of string created by esv::wstr_new must be destroyed by delete . delete [] s1; delete [] s2; delete [] s3; delete [] s4; }