Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pure beauty

23 views
Skip to first unread message

Bonita Montero

unread,
Aug 31, 2023, 2:59:22 PM8/31/23
to
I wrote a small Win32 tool that combines time from Unix, start
from Windows and runas from Windows in one. For this I just needed
a function that processes the number of clock cycles spent by the
process into a string. I wanted to use iterator debugging as much
as possible so that the whole thing is as good as safe from out
-of-bound errors. Here is the function:

string formatClockCycles( uint64_t clockCycles, char separator )
{
char digits[32];
auto [end, ec] = to_chars( digits, std::end( digits ), clockCycles );
string_view svDigits( digits, end );
size_t dots = (svDigits.length() - 1) / 3;
string_view::iterator itDigits = svDigits.end();
string dottified;
dottified.resize( svDigits.length() + dots, '*' );
string::iterator itRet = dottified.end();
for( ; dots--; itDigits -= 3, itRet -= 4 )
copy( itDigits - 3, itDigits, itRet - 3 ),
itRet[-4] = separator;
copy( svDigits.begin(), itDigits, dottified.begin() );
return dottified;
}
Message has been deleted
0 new messages