From 186f6a97437b872c81cfb24869ec5f3d8f787802 Mon Sep 17 00:00:00 2001 From: Hattrick HttrckCldHKS Date: Tue, 20 Sep 2022 00:14:47 +0300 Subject: [PATCH] Improve style --- Funcs.cpp | 409 ++++++++++++++---------------------------------------- Funcs.h | 74 +++++----- Main.cpp | 105 ++------------ 3 files changed, 154 insertions(+), 434 deletions(-) diff --git a/Funcs.cpp b/Funcs.cpp index 626023e..ab08020 100644 --- a/Funcs.cpp +++ b/Funcs.cpp @@ -1,306 +1,105 @@ -#include "Funcs.h" - -::std::string AddCommasA ( bool W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( char W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( short W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( int W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( long W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( long long W ) noexcept -{ - static ::std::string R { }, T { }; - static unsigned long long L { }, I { }, D { }; - - if ( W < 0I64 ) - R = '-', T = ::std::to_string ( ::std::abs ( W ) ); - - else - R.clear ( ), T = ::std::to_string ( W ); - - L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ), I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += ','; - } - - return R; -} - -::std::string AddCommasA ( unsigned char W ) noexcept -{ - return ::AddCommasA ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::string AddCommasA ( unsigned short W ) noexcept -{ - return ::AddCommasA ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::string AddCommasA ( unsigned int W ) noexcept -{ - return ::AddCommasA ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::string AddCommasA ( unsigned long W ) noexcept -{ - return ::AddCommasA ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::string AddCommasA ( unsigned long long W ) noexcept -{ - static ::std::string R { }, T { }; - static unsigned long long L { }, I { }, D { }; - - R.clear ( ), T = ::std::to_string ( W ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ), I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += ','; - } - - return R; -} - -::std::string AddCommasA ( float W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long double > ( W ) ) ); -} - -::std::string AddCommasA ( double W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long double > ( W ) ) ); -} - -::std::string AddCommasA ( long double W ) noexcept -{ - static ::std::string R { }, T { }, C { }; - static unsigned long long L { }, P { }, I { }, D { }; - - if ( W < 0.L ) - R = '-', T = ::std::to_string ( ::std::abs ( W ) ); - - else - R.clear ( ), T = ::std::to_string ( W ); - - L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - if ( ( ( P = ( static_cast < decltype ( P ) > ( T.find ( '.' ) ) ) ) >= 0UI64 ) && ( P < L ) ) - C.assign ( &( T [ P ] ) ), T.erase ( P ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - else if ( ( ( P = ( static_cast < decltype ( P ) > ( T.find ( ',' ) ) ) ) >= 0UI64 ) && ( P < L ) ) - T [ P ] = '.', C.assign ( &( T [ P ] ) ), T.erase ( P ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - else - C.clear ( ); - - I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += ','; - } - - return ( R + C ); -} - -::std::string AddCommasA ( char8_t W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( char16_t W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( char32_t W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::string AddCommasA ( wchar_t W ) noexcept -{ - return ::AddCommasA ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( bool W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( char W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( short W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( int W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( long W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( long long W ) noexcept -{ - static ::std::wstring R { }, T { }; - static unsigned long long L { }, I { }, D { }; - - if ( W < 0I64 ) - R = L'-', T = ::std::to_wstring ( ::std::abs ( W ) ); - - else - R.clear ( ), T = ::std::to_wstring ( W ); - - L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ), I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += L','; - } - - return R; -} - -::std::wstring AddCommasW ( unsigned char W ) noexcept -{ - return ::AddCommasW ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( unsigned short W ) noexcept -{ - return ::AddCommasW ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( unsigned int W ) noexcept -{ - return ::AddCommasW ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( unsigned long W ) noexcept -{ - return ::AddCommasW ( ( static_cast < unsigned long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( unsigned long long W ) noexcept -{ - static ::std::wstring R { }, T { }; - static unsigned long long L { }, I { }, D { }; - - R.clear ( ), T = ::std::to_wstring ( W ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ), I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += L','; - } - - return R; -} - -::std::wstring AddCommasW ( float W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long double > ( W ) ) ); -} - -::std::wstring AddCommasW ( double W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long double > ( W ) ) ); -} - -::std::wstring AddCommasW ( long double W ) noexcept -{ - static ::std::wstring R { }, T { }, C { }; - static unsigned long long L { }, P { }, I { }, D { }; - - if ( W < 0.L ) - R = L'-', T = ::std::to_wstring ( ::std::abs ( W ) ); - - else - R.clear ( ), T = ::std::to_wstring ( W ); - - L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - if ( ( ( P = ( static_cast < decltype ( P ) > ( T.find ( L'.' ) ) ) ) >= 0UI64 ) && ( P < L ) ) - C.assign ( &( T [ P ] ) ), T.erase ( P ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - else if ( ( ( P = ( static_cast < decltype ( P ) > ( T.find ( L',' ) ) ) ) >= 0UI64 ) && ( P < L ) ) - T [ P ] = L'.', C.assign ( &( T [ P ] ) ), T.erase ( P ), L = ( static_cast < decltype ( L ) > ( T.length ( ) ) ); - - else - C.clear ( ); - - I = 0UI64; - - while ( I < L ) - { - R += T [ I++ ]; - - if ( ( ( D = ( L - I ) ) != 0UI64 ) && ( ( D % 3UI64 ) == 0UI64 ) ) - R += L','; - } - - return ( R + C ); -} - -::std::wstring AddCommasW ( char8_t W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( char16_t W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( char32_t W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} - -::std::wstring AddCommasW ( wchar_t W ) noexcept -{ - return ::AddCommasW ( ( static_cast < long long > ( W ) ) ); -} +#include "Funcs.h" + +::std::string AddCommasA(bool W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(char W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(short W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(int W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(long W) noexcept { return ::AddCommasA((static_cast (W))); } + +::std::string AddCommasA(long long W) noexcept { + static ::std::string R{ }, T{ }; static unsigned long long L{ }, I{ }, D{ }; + if (W < 0I64) R = '-', T = ::std::to_string(::std::abs(W)); + else R.clear(), T = ::std::to_string(W); + L = (static_cast (T.length())), I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += ','; + } return R; +} + +::std::string AddCommasA(unsigned char W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(unsigned short W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(unsigned int W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(unsigned long W) noexcept { return ::AddCommasA((static_cast (W))); } + +::std::string AddCommasA(unsigned long long W) noexcept { + static ::std::string R{ }, T{ }; static unsigned long long L{ }, I{ }, D{ }; + R.clear(), T = ::std::to_string(W), L = (static_cast (T.length())), I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += ','; + } return R; +} + +::std::string AddCommasA(float W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(double W) noexcept { return ::AddCommasA((static_cast (W))); } + +::std::string AddCommasA(long double W) noexcept { + static ::std::string R{ }, T{ }, C{ }; static unsigned long long L{ }, P{ }, I{ }, D{ }; + if (W < 0.L) R = '-', T = ::std::to_string(::std::abs(W)); + else R.clear(), T = ::std::to_string(W); + L = (static_cast (T.length())); + if (((P = (static_cast (T.find('.')))) >= 0UI64) && (P < L)) + C.assign(&(T[P])), T.erase(P), L = (static_cast (T.length())); + else if (((P = (static_cast (T.find(',')))) >= 0UI64) && (P < L)) + T[P] = '.', C.assign(&(T[P])), T.erase(P), L = (static_cast (T.length())); + else C.clear(); I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += ','; + } return (R + C); +} + +::std::string AddCommasA(char8_t W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(char16_t W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(char32_t W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::string AddCommasA(wchar_t W) noexcept { return ::AddCommasA((static_cast (W))); } +::std::wstring AddCommasW(bool W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(char W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(short W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(int W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(long W) noexcept { return ::AddCommasW((static_cast (W))); } + +::std::wstring AddCommasW(long long W) noexcept { + static ::std::wstring R{ }, T{ }; static unsigned long long L{ }, I{ }, D{ }; + if (W < 0I64) R = L'-', T = ::std::to_wstring(::std::abs(W)); + else R.clear(), T = ::std::to_wstring(W); + L = (static_cast (T.length())), I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += L','; + } return R; +} + +::std::wstring AddCommasW(unsigned char W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(unsigned short W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(unsigned int W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(unsigned long W) noexcept { return ::AddCommasW((static_cast (W))); } + +::std::wstring AddCommasW(unsigned long long W) noexcept { + static ::std::wstring R{ }, T{ }; static unsigned long long L{ }, I{ }, D{ }; + R.clear(), T = ::std::to_wstring(W), L = (static_cast (T.length())), I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += L','; + } return R; +} + +::std::wstring AddCommasW(float W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(double W) noexcept { return ::AddCommasW((static_cast (W))); } + +::std::wstring AddCommasW(long double W) noexcept { + static ::std::wstring R{ }, T{ }, C{ }; static unsigned long long L{ }, P{ }, I{ }, D{ }; + if (W < 0.L) R = L'-', T = ::std::to_wstring(::std::abs(W)); + else R.clear(), T = ::std::to_wstring(W); + L = (static_cast (T.length())); + if (((P = (static_cast (T.find(L'.')))) >= 0UI64) && (P < L)) + C.assign(&(T[P])), T.erase(P), L = (static_cast (T.length())); + else if (((P = (static_cast (T.find(L',')))) >= 0UI64) && (P < L)) + T[P] = L'.', C.assign(&(T[P])), T.erase(P), L = (static_cast (T.length())); + else C.clear(); I = 0UI64; + while (I < L) { + R += T[I++]; if (((D = (L - I)) != 0UI64) && ((D % 3UI64) == 0UI64)) R += L','; + } return (R + C); +} + +::std::wstring AddCommasW(char8_t W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(char16_t W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(char32_t W) noexcept { return ::AddCommasW((static_cast (W))); } +::std::wstring AddCommasW(wchar_t W) noexcept { return ::AddCommasW((static_cast (W))); } diff --git a/Funcs.h b/Funcs.h index 36803d0..28340ac 100644 --- a/Funcs.h +++ b/Funcs.h @@ -1,42 +1,42 @@ #pragma once -#include < string > +#include -::std::string AddCommasA ( bool ) noexcept; -::std::string AddCommasA ( char ) noexcept; -::std::string AddCommasA ( short ) noexcept; -::std::string AddCommasA ( int ) noexcept; -::std::string AddCommasA ( long ) noexcept; -::std::string AddCommasA ( long long ) noexcept; -::std::string AddCommasA ( unsigned char ) noexcept; -::std::string AddCommasA ( unsigned short ) noexcept; -::std::string AddCommasA ( unsigned int ) noexcept; -::std::string AddCommasA ( unsigned long ) noexcept; -::std::string AddCommasA ( unsigned long long ) noexcept; -::std::string AddCommasA ( float ) noexcept; -::std::string AddCommasA ( double ) noexcept; -::std::string AddCommasA ( long double ) noexcept; -::std::string AddCommasA ( char8_t ) noexcept; -::std::string AddCommasA ( char16_t ) noexcept; -::std::string AddCommasA ( char32_t ) noexcept; -::std::string AddCommasA ( wchar_t ) noexcept; +::std::string AddCommasA(bool) noexcept; +::std::string AddCommasA(char) noexcept; +::std::string AddCommasA(short) noexcept; +::std::string AddCommasA(int) noexcept; +::std::string AddCommasA(long) noexcept; +::std::string AddCommasA(long long) noexcept; +::std::string AddCommasA(unsigned char) noexcept; +::std::string AddCommasA(unsigned short) noexcept; +::std::string AddCommasA(unsigned int) noexcept; +::std::string AddCommasA(unsigned long) noexcept; +::std::string AddCommasA(unsigned long long) noexcept; +::std::string AddCommasA(float) noexcept; +::std::string AddCommasA(double) noexcept; +::std::string AddCommasA(long double) noexcept; +::std::string AddCommasA(char8_t) noexcept; +::std::string AddCommasA(char16_t) noexcept; +::std::string AddCommasA(char32_t) noexcept; +::std::string AddCommasA(wchar_t) noexcept; -::std::wstring AddCommasW ( bool ) noexcept; -::std::wstring AddCommasW ( char ) noexcept; -::std::wstring AddCommasW ( short ) noexcept; -::std::wstring AddCommasW ( int ) noexcept; -::std::wstring AddCommasW ( long ) noexcept; -::std::wstring AddCommasW ( long long ) noexcept; -::std::wstring AddCommasW ( unsigned char ) noexcept; -::std::wstring AddCommasW ( unsigned short ) noexcept; -::std::wstring AddCommasW ( unsigned int ) noexcept; -::std::wstring AddCommasW ( unsigned long ) noexcept; -::std::wstring AddCommasW ( unsigned long long ) noexcept; -::std::wstring AddCommasW ( float ) noexcept; -::std::wstring AddCommasW ( double ) noexcept; -::std::wstring AddCommasW ( long double ) noexcept; -::std::wstring AddCommasW ( char8_t ) noexcept; -::std::wstring AddCommasW ( char16_t ) noexcept; -::std::wstring AddCommasW ( char32_t ) noexcept; -::std::wstring AddCommasW ( wchar_t ) noexcept; +::std::wstring AddCommasW(bool) noexcept; +::std::wstring AddCommasW(char) noexcept; +::std::wstring AddCommasW(short) noexcept; +::std::wstring AddCommasW(int) noexcept; +::std::wstring AddCommasW(long) noexcept; +::std::wstring AddCommasW(long long) noexcept; +::std::wstring AddCommasW(unsigned char) noexcept; +::std::wstring AddCommasW(unsigned short) noexcept; +::std::wstring AddCommasW(unsigned int) noexcept; +::std::wstring AddCommasW(unsigned long) noexcept; +::std::wstring AddCommasW(unsigned long long) noexcept; +::std::wstring AddCommasW(float) noexcept; +::std::wstring AddCommasW(double) noexcept; +::std::wstring AddCommasW(long double) noexcept; +::std::wstring AddCommasW(char8_t) noexcept; +::std::wstring AddCommasW(char16_t) noexcept; +::std::wstring AddCommasW(char32_t) noexcept; +::std::wstring AddCommasW(wchar_t) noexcept; diff --git a/Main.cpp b/Main.cpp index 46e65fd..c6a0324 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,96 +1,17 @@ -#include < iostream > - -#include "Funcs.h" - -#include < windows.h > - -int __cdecl wmain ( void ) noexcept -{ - ::Sleep ( 8192 ); - - long long S [ ] - { - -9999999999I64, - -999999999I64, - -99999999I64, - -9999999I64, - -999999I64, - -99999I64, - -9999I64, - -999I64, - -99I64, - -9I64, - 0I64, - 9I64, - 99I64, - 999I64, - 9999I64, - 99999I64, - 999999I64, - 9999999I64, - 99999999I64, - 999999999I64, - 9999999999I64, - }; - - unsigned long long U [ ] - { - 0UI64, - 9UI64, - 99UI64, - 999UI64, - 9999UI64, - 99999UI64, - 999999UI64, - 9999999UI64, - 99999999UI64, - 999999999UI64, - 9999999999UI64, - }; - - long double R [ ] - { - -9999999999.9L, - -999999999.9L, - -99999999.9L, - -9999999.9L, - -999999.9L, - -99999.9L, - -9999.9L, - -999.9L, - -99.9L, - -9.9L, - -.9L, - 0.L, - .9L, - 9.9L, - 99.9L, - 999.9L, - 9999.9L, - 99999.9L, - 999999.9L, - 9999999.9L, - 99999999.9L, - 999999999.9L, - 9999999999.9L, - }; - - for ( auto & V : S ) - ::std::wcout << ::AddCommasW ( V ) << ::std::endl; - - ::std::wcout << ::std::endl; - - for ( auto & V : U ) - ::std::wcout << ::AddCommasW ( V ) << ::std::endl; - - ::std::wcout << ::std::endl; - - for ( auto & V : R ) - ::std::wcout << ::AddCommasW ( V ) << ::std::endl; - - ::std::wcout << ::std::endl; - +#include +#include "Funcs.h" +#include + +int __cdecl wmain() noexcept { + ::Sleep(8192UL); long long S[]{ -9999999999I64, -999999999I64, -99999999I64, -9999999I64, -999999I64, -99999I64, -9999I64, -999I64, -99I64, -9I64, + 0I64, 9I64, 99I64, 999I64, 9999I64, 99999I64, 999999I64, 9999999I64, 99999999I64, 999999999I64, 9999999999I64, + }; unsigned long long U[]{ 0UI64, 9UI64, 99UI64, 999UI64, 9999UI64, 99999UI64, 999999UI64, 9999999UI64, 99999999UI64, 999999999UI64, 9999999999UI64, + }; long double R[]{ -9999999999.9L, -999999999.9L, -99999999.9L, -9999999.9L, -999999.9L, -99999.9L, -9999.9L, -999.9L, -99.9L, -9.9L, -.9L, + 0.L, .9L, 9.9L, 99.9L, 999.9L, 9999.9L, 99999.9L, 999999.9L, 9999999.9L, 99999999.9L, 999999999.9L, 9999999999.9L, + }; for (auto& V : S) ::std::wcout << ::AddCommasW(V) << ::std::endl << ::std::endl; + for (auto& V : U) ::std::wcout << ::AddCommasW(V) << ::std::endl << ::std::endl; + for (auto& V : R) ::std::wcout << ::AddCommasW(V) << ::std::endl << ::std::endl; return 0I32; }