✨⚡️ xeerx C++ Format Library ⚡️✨
An excellent quick c++ library for managing and formatting strings with the power to transform from/to any sort
-
♻️ Cross-Platform – examined by
Google Take a look at
. -
⚡️ Velocity – sooner than
std::string
,std::time
,std::to_chars
,{fmt}
, .., examined byGoogle Benchmark
. -
🍃 Gentle – minimal traces of code, fast compiling, examined by
GCC 12
. -
✨ optimization – improved conduct to scale back
Reminiscence Allocation
, examined byValgrind
. -
🌟 Skill – works with a whole lot of knowledge varieties
any char
numbers
time
bool
..and so forth.
🔹🔹 you’ll discover
take a look at
,gtest
andbenchmark
for every little thing in:checks/
🔹🔹
Index
The library comprises:
- xeerx::string quickest string class.
- xeerx::to_chars, chars_to quickest numbers-strings conversion capabilities.
- xeerx::time, xeerx::stime quickest time lessons.
- xeerx::format quickest formatting perform.
- xeerx::exception to throw an exception with details about it.
Utilization
#embrace "core.h"
utilizing namespace xeerx;
-
String
How It Works
To grasp how strings work, let’s examine the next examples:
// [1] xeerx::string s1 ("Howdy World"); // [2] xeerx::string s2 ("Howdy"); s2 += "World"; // [3] xeerx::string s3 ("chars:"); for(int i = 0; i < 100; i++) s3 += 'C';
Rationalization of examples
- ### First Instance
On this case the category will simply pointing to the worth, likestd::string_view
so there isn’t any copies, identical to regularconst char*
-
Second Instance
1- pointing to the worth
Howdy
2- copy
Howdy
to thestack buffer
3- copy
World
to the top ofstack buffer
to beHelloWorld
-
Third Instance
1- pointing to the worth
chars:
2- copy
chars:
to thestack buffer
now we have to append
C
x100 instances, and ourstack buffer
dimension is64
and the present dimension of the buffer is
6
(chars:
is6
characters)so the stack can maintain extra
64 - 6 = 58
characters3- copy
C
58 instances
to the top ofstack buffer
now the
stack buffer
is full and we have to append extra42
charactersso allocate an sufficient area within the heap reminiscence known as
heap buffer
4- allocate an area within the heap reminiscence
5- copy contents of
stack buffer
to theheap buffer
6- append the remaining
42
characters to the top of theheap buffer
Typedefs
Kind Definition xeerx::string xeerx::basic_string< char
>xeerx::wstring xeerx::basic_string< wchar_t
>xeerx::u16string xeerx::basic_string< char16_t
>xeerx::u32string xeerx::basic_string< char32_t
>- ### Specialization Varieties
// prototype template<typename Kind, class Alloc = std::allocator<Kind>, xeerx::size_t L_Capacity = X_BUFF_SIZE> xeerx::basic_string<Kind, Alloc, L_Capacity> // instance: basic_string for 'char' with native buffer capability 256 typedef xeerx::basic_string<char, std::allocator<char>, 256> string_256;
There are two sorts of characters allowed,
char
andwchar_t
.However you should utilize any sort of character as a result of the category takes tamplate parameter to know what sort of character to make use of,
BUT I am undecided about something besides
char
andwchar_t
so you need to attempt to take a look at it your self.Macros
Identify Worth Definition X_BUFF_SIZE
64UL default dimension of the native buffer Exceptions
Exception Definition std::length_error
when the scale of the string >= xeex::size_t_max
std::out_of_range
when the index of the string > dimension()
Template Parameters
Parameter Definition Kind character sort Alloc Allocator sort used to allocate inner storage Member Varieties
Kind Definition chars xeerx::char_traits<Kind>
value_type Kind
size_type _traits::size_type xeerx::size_t
reference _traits::reference Kind&
const_reference _traits::const_reference const Kind&
pointer _traits::pointer Kind*
const_pointer _traits::const_pointer const Kind*
iterator _traits::iterator Kind*
const_iterator _traits::const_iterator const Kind*
Member Capabilities
-
constructor’s | destructor
🔹 Examples 🔹
// empty constructor string s0; // 👉 "" // assign constructor utilizing array of characters string s1("Howdy"); // 👉 "Howdy" // assign constructor utilizing single character string s2('C'); // 👉 "C" // assign constructor utilizing vary (iterators) string s3(s1.cbegin(), s1.cend()); // 👉 "Howdy" // assign constructor utilizing bool string s4(true); // 👉 "true" // assign constructor utilizing integer (see convert perform for extra particulars) string s5(123); // 👉 "123" // assign constructor utilizing float (see convert perform for extra particulars) string s6(0.14); // 👉 "0.14" // copy constructor string s7(s1); // 👉 "Howdy" // transfer constructor string s8(std::transfer(s1)); // 👉 "Howdy"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 0.976 ns 689897792 ⚡️ 1.0 empty constructor 🔸 std::string 0.978 ns 704357784 🔹 xeerx::string 1.30 ns 531657012 ⚡️ 2.2 copy constructor 🔸 std::string 2.93 ns 238350514 🔹 xeerx::string 1.30 ns 532291700 ⚡️ 4.7 transfer constructor 🔸 std::string 6.15 ns 110840133 🔹 xeerx::string 1.30 ns 473253168 ⚡️ 1.7 array constructor 🔸 std::string 2.26 ns 356990635 🔹 xeerx::string 1.41 ns 427177908 ⚡️ 8.0 single char constructor 🔸 std::string 11.3 ns 62462721 🔹 xeerx::string 2.45 ns 292649634 ⚡️ 1.6 vary constructor 🔸 std::string 3.93 ns 186850707 🔹 xeerx::string 1.97 ns 344396141 ⚡️ — bool constructor 🔸 std::string — ns ——— 🔹 xeerx::string 3.02 ns 234255879 ⚡️ 2.0 lengthy int constructor 🔸 std::string 6.31 ns 109529125 🔹 xeerx::string 8.13 ns 84837465 ⚡️ 2.8 brief int constructor 🔸 std::string 22.9 ns 30325927 🔹 xeerx::string 2.60 ns 267951182 ⚡️ 75.3 lengthy float constructor 🔸 std::string 196 ns 3535237 🔹 xeerx::string 3.26 ns 214303767 ⚡️ 61.0 brief float constructor 🔸 std::string 199 ns 3511556 🌟
std::to_string
cannot convert bool to string. -
Copy | Transfer | Swap
🔹 Examples 🔹
string s("Howdy World"); string s1; s1.copy(s); // 👉 "Howdy World" string s2; s2.transfer(std::transfer(s)); // 👉 "Howdy World" string s3; s3.swap(s); // 👉 "Howdy World"
🔸 Benchmark 🔸
no benchmark want on this part, you’ll be able to see
constructor
part to search outcopy
andtransfer
benchmark, as aboutswap
is simplystd::swap
. -
Assign
🔹 Examples 🔹
string s; string s1("One other String"); // assign utilizing array of characters s.assign("Howdy"); // 👉 "Howdy" // assign utilizing single character s.assign('C'); // 👉 "C" // assign utilizing vary (iterators) s.assign(s1.cbegin(), s1.cend()); // 👉 "One other String" // assign utilizing bool s.assign(true); // 👉 "true" // assign utilizing integer (see convert perform for extra particulars) s.assign(123); // 👉 "123" // assign utilizing float (see convert perform for extra particulars) s.assign(0.14); // 👉 "0.14" // assign utilizing one other string s.assign(s1); // 👉 "One other String"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 1.34 ns 531380206 ⚡️ 2.2 assign utilizing string 🔸 std::string 2.93 ns 238106163 🔹 xeerx::string 1.31 ns 528827390 ⚡️ 6.7 assign utilizing array 🔸 std::string 8.81 ns 78799728 🔹 xeerx::string 1.31 ns 534289066 ⚡️ 8.6 assign utilizing single char 🔸 std::string 11.3 ns 61128346 🔹 xeerx::string 2.28 ns 306184756 ⚡️ 4.3 assign utilizing vary 🔸 std::string 9.90 ns 69530909 🔹 xeerx::string 1.95 ns 357179984 ⚡️ — assign utilizing bool 🔸 std::string — ns ——— 🔹 xeerx::string 9.09 ns 75920717 ⚡️ 2.0 assign utilizing lengthy int 🔸 std::string 18.7 ns 37284998 🔹 xeerx::string 3.54 ns 169905048 ⚡️ 1.0 assign utilizing brief int 🔸 std::string 3.91 ns 195297191 🔹 xeerx::string 3.59 ns 195349150 ⚡️ 56.5 assign utilizing lengthy float 🔸 std::string 203 ns 3436025 🔹 xeerx::string 2.61 ns 268187597 ⚡️ 76.6 assign utilizing brief float 🔸 std::string 200 ns 3430881 🌟
std::to_string
cannot convert bool to string. -
Convert
This perform utilizing
xeerx::to_chars
to transformSo for extra info see the conversion part
🔹 Examples 🔹
// integer string s1; s1.convert(123); // 👉 "123" // integer base string s2; s2.convert(123, 16); // 👉 "7b" // signal string s3; s3.convert(123, 16, '+'); // 👉 "+7b" // letter case string s4; s4.convert(123, 16, '+', tail, 1); // 👉 "+7B" // float string s5; s5.convert(3.987); // 👉 "3.98" // float precision string s6; s6.convert(3.987, 3); // 👉 "3.987" // float trailing zeros string s7; s7.convert(1.09800, 5, '+', 1); // 👉 "+1.09800" string s8; s8.convert(1.09800, 5, '+', 0); // 👉 "+1.098"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 2.49 ns 280885493 ⚡️ — convert utilizing bool 🔸 std::string — ns ——— 🔹 xeerx::string 9.13 ns 75557257 ⚡️ 5.6 convert utilizing lengthy int 🔸 std::string 52.0 ns 13533688 🔹 xeerx::string 4.40 ns 163482392 ⚡️ 3.3 convert utilizing brief int 🔸 std::string 14.8 ns 46670954 🔹 xeerx::string 3.62 ns 195510099 ⚡️ 57.4 convert utilizing lengthy float 🔸 std::string 208 ns 3371255 🔹 xeerx::string 2.93 ns 238643277 ⚡️ 69.9 convert utilizing brief float 🔸 std::string 205 ns 3402302 🌟
std::to_string
cannot convert bool to string. -
Append
🔹 Examples 🔹
string s; string s1("One other String"); // append utilizing array of characters s.append("Howdy"); // 👉 "Howdy" // append utilizing single character s.append('C'); // 👉 "...C" // append utilizing vary (iterators) s.append(s1.cbegin(), s1.cend()); // 👉 "...One other String" // append utilizing bool s.append(true); // 👉 "...true" // append utilizing integer (see convert perform for extra particulars) s.append(123); // 👉 "...123" // append utilizing float (see convert perform for extra particulars) s.append(0.14); // 👉 "...0.14" // append utilizing one other string s.append(s1); // 👉 "...One other String"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 45.0 ns 16190001 ⚡️ 2.2 append utilizing string 🔸 std::string 103 ns 6637803 🔹 xeerx::string 38.2 ns 18203461 ⚡️ 2.5 append utilizing array 🔸 std::string 96.0 ns 7101166 🔹 xeerx::string 21.0 ns 32952515 ⚡️ 2.2 append utilizing single char 🔸 std::string 46.8 ns 14844033 🔹 xeerx::string 44.0 ns 15887083 ⚡️ 2.7 append utilizing vary 🔸 std::string 122 ns 5548724 🔹 xeerx::string 20.9 ns 34528601 ⚡️ — append utilizing bool 🔸 std::string — ns ——— 🔹 xeerx::string 116 ns 5953486 ⚡️ 2.6 append utilizing lengthy int 🔸 std::string 307 ns 2270919 🔹 xeerx::string 75.4 ns 9182231 ⚡️ 1.0 append utilizing brief int 🔸 std::string 80.4 ns 8533531 🔹 xeerx::string 68.6 ns 9908682 ⚡️ 33.1 append utilizing lengthy float 🔸 std::string 2253 ns 308565 🔹 xeerx::string 30.3 ns 22941116 ⚡️ 74.4 append utilizing brief float 🔸 std::string 2242 ns 314610 🌟
std::to_string
cannot convert bool to string. -
Insert
🔹 Examples 🔹
Yow will discover the take a look at script in
/checks/insert-string.cpp
to verify it your self.string s("15 : "); // insert utilizing single character s.insert(0, '0'); // 👉 "015 : " // insert utilizing array of characters s.insert(2, "234"); // 👉 "012345 : " // insert utilizing one other string s.insert(s.dimension(), s); // 👉 "012345 : 012345 : " // insert utilizing vary (iterators) string s1("Iterator"); s.insert(s.dimension(), s1.cbegin(), s1.cend()); // 👉 "012345 : 012345 : Iterator"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 90.9 ns 7302295 ⚡️ 1.5 insert utilizing string 🔸 std::string 143 ns 4852644 🔹 xeerx::string 92.3 ns 7438356 ⚡️ 1.3 insert utilizing array 🔸 std::string 124 ns 5604204 🔹 xeerx::string 59.6 ns 11534530 ⚡️ 1.4 insert utilizing single char 🔸 std::string 83.2 ns 8121425 🔹 xeerx::string 44.0 ns 7648863 ⚡️ — insert utilizing vary 🔸 std::string — ns ——— 🌟 there isn’t any perform to insert utilizing vary in
std::string
. -
Fill
🔹 Examples 🔹
string s; // string just isn't initialized but, so append `C` * 10 instances s.fill('C', 0, 10); // 👉 "CCCCCCCCCC" // string is initialized, so change vary(0,9) with `M` s.fill('M', 0, 10); // 👉 "MMMMMMMMMM"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 13.9 ns 49118574 ⚡️ 2.6 fill utilizing character 🔸 std::string 37.0 ns 18117575 🌟 there isn’t any perform to fill in
std::string
, so i usedchange
in benchmark. -
Substitute
🔹 Examples 🔹
// size of "AB" = 2, size of vary to interchange is (6-4) = 2 // so change "45" with "AB" string s1("0123456789"); s1.change("AB", 4, 6); // 👉 "0123AB6789" // size of "A" = 1, size of vary to interchange is (6-4) = 2 // so change "4" with "A" // and transfer "6789" to backward by one. // in one other phrase, change "45" with "A" string s2("0123456789"); s2.change("A", 4, 6); // 👉 "0123A6789" // size of "HelloWorld" = 10, size of vary to interchange is (6-4) = 2 // so transfer "6789" to ahead by (10 - 2) = 8. // and change "45 " with "HelloWorld" // in one other phrase, change "45" with "HelloWorld" string s3("0123456789"); s3.change("HelloWorld", 4, 6); // 👉 "0123HelloWorld6789"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 35.5 ns 19680601 ⚡️ 1.3 change utilizing array 🔸 std::string 46.5 ns 15060716 -
Erase
🔹 Examples 🔹
string s("0123456789"); s.erase(4, 2); // 👉 "01236789"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 9.36 ns 74738109 ⚡️ 2.2 erase a part of string 🔸 std::string 21.2 ns 32678576 -
Clear
🔹 Examples 🔹
string s("0123456789"); s.clear(); // 👉 ""
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 1.30 ns 536039461 ⚡️ 12.6 clear string contents 🔸 std::string 16.4 ns 40010757 -
Resize
🔹 Examples 🔹
string s("0123456789"); s.resize(5); // 👉 "01234"
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 2.86 ns 267733338 ⚡️ 6.3 resize string dimension 🔸 std::string 18.2 ns 36673351 -
Reserve
🔹 Examples 🔹
string s; s.reserve(100); // 👉 heap capability now could be 100
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 16.1 ns 44328723 ⚡️ 2.1 reserve area within the heap 🔸 std::string 35.3 ns 19861444 -
Evaluate
🔹 Examples 🔹
string s("Howdy"); s.evaluate("Howdy"); // 👉 0 s.evaluate("whats up"); // 👉 -32 s.evaluate("Blah" ); // 👉 6
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 1.63 ns 425109330 ⚡️ 1.2 evaluate two strings 🔸 std::string 1.97 ns 354517169 -
Discover
🔹 Examples 🔹
string s("12 13 12 14"); // discover utilizing array s.discover("12", 0); // 👉 0 s.discover("12", 2); // 👉 6 // discover utilizing character s.discover('3' , 0); // 👉 4
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::string 1.30 ns 519393604 ⚡️ 12.8 discover utilizing array 🔸 std::string 16.7 ns 41623313 🔹 xeerx::string 1.30 ns 532126470 ⚡️ 12.7 discover utilizing character 🔸 std::string 16.6 ns 41633714 -
Letter Case Management
🔹 Examples 🔹
string s("whats up World s S 123"); // all to higher case s.higher(); // 👉 "HELLO WORLD S S 123" // all to decrease case s.decrease(); // 👉 "whats up world s s 123" // make all phrases begin with higher case character s.wupper(); // 👉 "Howdy World s S 123"
-
Entry Capabilities
🔹 Learn-Solely 🔹
string.cdata(); // Buffer of characters string.cbegin(); // Start iterator string.cend(); // Finish iterator string.dimension(); // Measurement of buffer string.max_size(); // Most dimension that may be accommodated string.capability(); // Capability of buffer string.empty(); // Examine if dimension == 0 string.cat(N); // Get character at place
🔹 Learn-Write 🔹
string.knowledge(); // Buffer of characters string.start(); // Start iterator string.finish(); // Finish iterator string.at(N); // Get character at place
🔸 Benchmark 🔸
no benchmark want on this part, all of this capabilities simply return to the non-public variables.
-
Operatores
🔹 copy-move 🔹
string A("Howdy"), B; B = A; // copy B = std::transfer(B); // transfer
🔹 assign 🔹
string S; S = "Howdy"; S = 123; S = ...; // identical as assign()
🔹 append 🔹
string S; S += "Howdy"; S += 123; S += ...; // identical as append()
🔹 append plus 🔹[The Power Of The Append]
string A("-> "), S; S += A + false + " 123" + 456 + ' ' + 3.14; // 👉 "-> false 123456 3.14" // [NOTE] A will likely be additionally "-> false 123456 3.14" // as a result of the information append to A primary, than to S // so you need to use a brief string within the first argument // What if i wish to add S1 and S2 to S3 with out change S1 and S2 ? string S1("Howdy"), S2("World"), S3; S3 = S1; S3 += S2; // like this S3 += string(S1) + S2; // or this
🔹 evaluate 🔹
string S1("Howdy"), S2("World"); bool is_same = (S1 == S2);
🔹 at 🔹
string S1("Howdy"); S1[0] = 'h';
🔹 stream 🔹
string S1("Howdy"); std::cout << S1 << std::endl;
🔸 Benchmark 🔸
no benchmark want on this part, operators do identical of it is perform, for instance
+=
nameappend
, ..and so forth.
- ### First Instance
-
Conversions
-
convert numbers to characters array
🔹 Examples 🔹
char c[11] = "N:xxxxxxxx"; // will be wchar_t or sort of characters // handbook size (overload with 'final' as a parameter) to_chars(c, c + sizeof(c), -10); // c 👉 "-10" // auto size (overload with 'final' as a template parameter) to_chars(c,-10); // c 👉 "-10" // [integer base] you should utilize any base between 2 and 36 to_chars(c,-123, 36); // c 👉 "-3f" to_chars(c,-123, 16); // c 👉 "-7b" to_chars(c,-123, 10); // c 👉 "-123" to_chars(c,-123, 8); // c 👉 "-173" to_chars(c,-123, 2); // c 👉 "-1111011" // [sign] to_chars(c, 1, 10, '+'); // c 👉 "+1" to_chars(c,-1, 10, '+'); // c 👉 "-1" to_chars(c, 1, 10, '-'); // c 👉 "1" to_chars(c,-1, 10, '-'); // c 👉 "-1" to_chars(c, 1, 10, ' '); // c 👉 " 1" to_chars(c,-1, 10, ' '); // c 👉 "-1" // [terminate array] to_chars(c, 1, 10, '+', 1); // c 👉 "+1" to_chars(c, 1, 10, '+', 0); // c 👉 "+1xxxxxxxx" // [floating precision] float f = -1.09800; to_chars(c,f); // c 👉 "-1.09" to_chars(c,f, 1); // c 👉 "-1.0" to_chars(c,f, 2); // c 👉 "-1.09" to_chars(c,f, 3); // c 👉 "-1.098" to_chars(c,f, 4); // c 👉 "-1.0980" // [trailing zeros] to_chars(c,f, 5, '+', 1, 0); // c 👉 "-1.098" to_chars(c,f, 5, '+', 1, 1); // c 👉 "-1.09800" // [trailing zeros] to_chars(c,f, 5, '+', 1, 0); // c 👉 "-1.098" to_chars(c,f, 5, '+', 1, 1); // c 👉 "-1.09800" // [letter case] to_chars(c,-123, 36, '+', 1, 1, 1); // c 👉 "-3F" to_chars(c,-123, 36, '+', 1, 1, 0); // c 👉 "-3f" // [length] if you recognize the size of the integer half, so put it in final argument to_chars(c,-123, 36, '+', 1, 1, 3); // c 👉 "-3F" // [return | exception] // 🟩 if successed return to final written place // 🟥 if failed return to xeerx::size_t_max // 🟧 if X_DEBUG macro is outlined, when failed will throw an exceptionx
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::to_chars 0.333 ns 1000000000 ⚡️243.8 lengthy float 🔸 std::to_chars 81.2 ns 8665522 🔹 xeerx::to_chars 0.327 ns 1000000000 ⚡️177.6 brief float 🔸 std::to_chars 58.1 ns 12034705 🔹 xeerx::to_chars 0.327 ns 1000000000 ⚡️ 3.9 lengthy int 🔸 std::to_chars 1.30 ns 531564683 🔹 xeerx::to_chars 0.326 ns 1000000000 ⚡️ 2.0 brief int 🔸 std::to_chars 0.652 ns 1000000000 -
convert characters array to numbers
🔹 Examples 🔹
chars_to<int>("-123"); // 👉 -123 // [integer base] you should utilize any base between 2 and 36 chars_to<int>("-3F", 36); // 👉 -123 chars_to<int>("-7B", 16); // 👉 -123 chars_to<int>("-123", 10); // 👉 -123 chars_to<int>("-173", 8); // 👉 -123 chars_to<int>("-1111011", 2); // 👉 -123 // [floating precision] chars_to<double>("-1.0098765"); // 👉 -1.00 chars_to<double>("-1.0098765", 1); // 👉 -1.0 chars_to<double>("-1.0098765", 2); // 👉 -1.00 chars_to<double>("-1.0098765", 3); // 👉 -1.009 chars_to<double>("-1.0098765", 4); // 👉 -1.0098 chars_to<double>("-1.0098765", 5); // 👉 -1.00986 chars_to<double>("-1.0098765", 6); // 👉 -1.009865 // [return | exception] // 🟩 if successed return to transformed worth // 🟥 if failed return to std::numeric_limits::max<N>() // 🟧 if X_DEBUG macro is outlined, when failed will throw an exceptionx
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::chars_to 0.327 ns 1000000000 ⚡️ 88.6 lengthy float 🔸 std::from_chars 29.0 ns 24078935 🔹 xeerx::chars_to 0.327 ns 1000000000 ⚡️ 1.6 brief float 🔸 std::from_chars 0.545 ns 1000000000 🔹 xeerx::chars_to 0.327 ns 1000000000 ⚡️ 4.0 lengthy int 🔸 std::from_chars 1.31 ns 533874680 🔹 xeerx::chars_to 0.328 ns 1000000000 ⚡️ 1.9 brief int 🔸 std::from_chars 0.652 ns 1000000000 -
-
Time
-
models
all models utilizing
std::chrono
second; milliseconds; microseconds; nanoseconds;
-
timestamp
timestamp<unit>(); // auto timestamp<unit>(1664697587); // handbook // members val; // timestamp worth fac; // issue (second = 1, mirosecond = 1000, ...)
-
essential time class
// auto time<second> t; // timestamp 👉 1664697587 , fac 👉 1 time<millisecond> t; // timestamp 👉 1664697587405 , fac 👉 1000 time<microsecond> t; // timestamp 👉 1664697587405492 , fac 👉 1000000 time<nanosecond> t; // timestamp 👉 1664697587405492704 , fac 👉 1000000000 // handbook time<second> t(1664697587); // timestamp -> 1664697587 , fac -> 1 // specification characters sort time<unit, char_type> t; // char_type by default is `char` // for string format use it stime<unit, char_type> t; // this can containts identical members of regular `time` class // along with the string members
-
numerical members
t.unit; // xeerx::timestamp object t.unit.val; // timestamp of unit : 👉 1664697587405492704 t.unit.fac; // issue of unit : 👉 1000000000 t.12 months; // 👉 2022 t.month; // 👉 10 t.week; // 👉 1 t.weekday; // 👉 2 t.day; // 👉 2 t.yday; // 👉 275 t.hour; // 👉 7 t.Hour; // 👉 7 t.minute; // 👉 59 t.second; // 👉 47 t.millisecond; // 👉 405 t.microsecond; // 👉 492 t.nanosecond; // 👉 704
-
string members
to get time members in string format you need to utilizing
stimg
as a substitute oftime
.t.num; // xeerx::time object, use it to entry the numerical members t.syear; // 👉 "2022" t.smonth; // 👉 "10" t.sweek; // 👉 "01" t.sweekday; // 👉 "02" t.sday; // 👉 "02" t.shour; // 👉 "07" t.sHour; // 👉 "07" t.sminute; // 👉 "59" t.ssecond; // 👉 "47" t.smillisecond; // 👉 "405" t.smicrosecond; // 👉 "492" t.snanosecond ; // 👉 "704" t.m; // 👉 "AM" // names t.nweekday; // 👉 "Solar" t.Nweekday; // 👉 "Sunday" t.nmonth; // 👉 "Oct" t.Nmonth; // 👉 "October"
-
convert between
time
andstime
// stime -> time time<nanosecond> t = stime<nanosecond>; // ERROR time<nanosecond> t = stime<nanosecond>().num; // OK // time -> stime stime<nanosecond> st = time<nanosecond>; // OK
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity 🔹 xeerx::time 13.2 ns 51969561 ⚡️ 200.7 🔹 xeerx::stime 29.4 ns 24039762 ⚡️ 90.1 🔸 local_time 2430 ns 293162 🔸 to_time_t 2844 ns 234573 🔸 asctime 2847 ns 250791 -
-
-
Formatting
-
Sample
-
prototype
// prototype // N -> What number of sections are there on this sample [for optimization] // C -> Kind of character fpattern<N, C = char> ("...");
-
arguments
// sequence argument fpattern<1>("{}"); // numbered argument fpattern<1>("{I}"); // mixture of sequence and numbered argument fpattern<4>("{1} {} {0} {}"); // [1] -> second "{1}" - (no impact on the final argument id) // [2] -> first "{}" (final argument id is 0, and will likely be 1) // [3] -> first "{0}" - (no impact on the final argument id) // [4] -> second "{}" (final argument id is 1, and will likely be 2) // management arguments fpattern<1>("{:}" || "{I:}"); // wrtie ':' to handle the argument // management integer base | float precision fpattern<1>("{:N}" || "{I:N}"); // for integer, 'N' will be any quantity between 2 and 36 (default is 10) // for float , 'N' will be any quantity between 1 and 36 (default is 2) // management letter case (With out specifying case, will probably be left as is) // [NOTE] letter case contoller works solely on integer's // when base numerical base > 10 fpattern<1>("{:NC}" || "{I:NC}"); // for all capital fpattern<1>("{:Nc}" || "{I:Nc}"); // for all small // management signal (see conversion part to know extra about signal's) fpattern<1>("{:SN}" || "{I:SN}"); // the ultimate sample fpattern<1>("{:SNC}" || "{I:SNC}"); // precision (Not Vital) // C -> letter case (Not Vital) // -> finish of part (Vital) /* ------------ Exceptions ------------ */ // std::invalid_argument("dangerous syntax") // [-] you need to write a number of specifier at the very least after the controller `:` // [-] you need to write the start '{' and the top '}' of the part // with out any-unknown character between it // the recognized characters is "I:SNC" // std::out_of_range("invalid argument id") // [-] 'I' can't be bigger than the template parameter 'N'
-
padding
// prototype fpattern<1>("{.AFV.}"); // {. -> start of padding part (Vital) // A -> padding align ['<', '>', '^'] (Not Vital) (default is left '<') // F -> padding fill [any char] (Vital) // V -> padding worth [any numbers] (Vital) // .} -> finish of padding part (Vital) // dynamic padding (with argument's and textual content inside it) fpattern<4>("{.^ 15IP:{}.},{.^ 15PORT:{}.}"); // IF IP is "127.0.0.1" && PORT is 443, so the end result will likely be prefer it: // --> "IP:127.0.0.1 ,PORT:443 " // regular padding (with out something inside it) fpattern<2>("{.*5.} IP:{}"); // --> "***** IP:127.0.0.1"
-
Examples
xeerx::format<N>
returns toxeerx::basic_string<char>
xeerx::format<C, N>
returns toxeerx::basic_string<C>
// sequence arguments 👉 "Howdy World" format<2>("{} {}", "Howdy", "World"); // numbered arguments 👉 "World Howdy, Howdy World" format<4>("{1} {0}, {0} {1}", "Howdy", "World"); // character 👉 "C, C" format<2>("{}, {}", 'C', 'c'); // bool 👉 "true, false" format<2>("{}, {}", true, false); // integer 👉 "123" format<1>("{}", 123); // integer base 👉 "d:123, x:7b, o:173, b:1111011, 36:3f" format<5>("d:{0:10}, x:{0:16}, o:{0:8}, b:{0:2}, 36:{0:36}", 123); // letter case 👉 "Capital:3F, Small:3f" format<2>("Capital:{0:36C}, Small:{0:36c}", 123); // float 👉 "3.14" format<1>("{}", 3.14); // float precision 👉 "3.01, 3.014, 3.0143" format<3>("{0:2}, {0:3}, {0:4}", 3.014321); // signal 👉 "+:[+1, 1, 1], -:[-1, -1, -1]" format<6>("+:[{0:+10}, {0:-10}, {0: 10}], -:[{1:+10}, {1:-10}, {1: 10}]", 1, -1); // multi varieties 👉 "string, C, true, -123, 3.14" format<5>("{}, {}, {}, {}, {}", "string", 'C', true, -123, 3.14);
padding examples
// empty padding 👉 "**********, true" format<2>("{.*10.}, {}", true); // left aligned 👉 "******true" format<2>("{.<*10{}.}", true); // proper aligned 👉 "true******" format<2>("{.>*10{}.}", true); // middle aligned 👉 "***true***" format<2>("{.^*10{}.}", true); // one other instance 👉 "[IP:127.0.0.1 ] [PORT:443 ]" format<4>("[{.> 15IP:{}.}] [{.> 15PORT:{}.}]", "127.0.0.1", 443);
-
🔸 Benchmark 🔸
Benchmark Time Iterations Velocity Kind 🔹 xeerx::format 3.70 ns 186586391 ⚡️ 52.9 left padding 🔸 fmt::format 196 ns 3545286 🔹 xeerx::format 3.70 ns 189126228 ⚡️ 54.3 proper padding 🔸 fmt::format 201 ns 3464272 🔹 xeerx::format 3.70 ns 188942568 ⚡️ 57.0 middle padding 🔸 fmt::format 211 ns 3304297 🔹 xeerx::format 2.69 ns 258969920 ⚡️ 9.9 one string 🔸 fmt::format 26.7 ns 26305344 🔹 xeerx::format 16.5 ns 42150231 ⚡️ 4.0 two strings 🔸 fmt::format 66.7 ns 10376705 🔹 xeerx::format 77.8 ns 8581737 ⚡️ 2.2 loads strings 🔸 fmt::format 174 ns 4061439 🔹 xeerx::format 2.69 ns 259762850 ⚡️ 14.3 signle character 🔸 fmt::format 38.6 ns 18119202 🔹 xeerx::format 10.8 ns 64446743 ⚡️ 5.3 bool 🔸 fmt::format 57.6 ns 11925818 🔹 xeerx::format 2.02 ns 346543561 ⚡️ 10.0 brief int 🔸 fmt::format 20.1 ns 34644407 🔹 xeerx::format 3.02 ns 231357308 ⚡️ 17.4 lengthy int 🔸 fmt::format 52.4 ns 13166775 🔹 xeerx::format 2.69 ns 252905827 ⚡️ 29.4 float 🔸 fmt::format 78.6 ns 9923260 -
Optimization with
constexpr fpattern
will probably be sooner by close to
30%
in lengthy and sophisticated patternsconstexpr fpattern<N> pat("..."); // then you'll be able to cross it to format perform like: format<N>(pat, ...);
-
-
Exceptions
0. void take a look at() 1. { 2. x_throw(exceptions::out_of_range); 3. } // output: // xeerx::exception::out_of_range // [FILE] /path/to/file.ext [LINE] 2 [FUNC] take a look at
```cpp
0. void take a look at()
1. { int pos = 21, dimension = 20;
2. x_throws(exceptions::out_of_range, format<2>("pos:{} >= dimension:{}", pos, dimension));
3. }
// output:
// xeerx::exception::out_of_range
// [FILE] /path/to/file.ext [LINE] 2 [FUNC] take a look at : pos:21 >= dimension:20
```
Benchmark Information
-
compiler:
GCC 12
-
c++ model:
20
-
operator system:
Ubuntu 22.04.1 LTS
-
processor:
Intel® Core™ i7-6500U CPU @ 2.50GHz × 4
-
flags:
-Ofast
Supply Code
yow will discover the supply code on Github
as a result of the supply code is huge and has loads script’s
so i can not put it right here.
This Submit Was Printed In Model 0.0.1
Updates
..
Hope I made one thing helpful
This model continues to be a beta model and I’ve not completed absolutely creating the library
So I want to know your opinion about this
-
Are there issues ?
-
Is there something that may be developed or added?
-
Did I do something flawed?
Thanks.