Bonita Montero
unread,Aug 31, 2023, 2:59:22 PM8/31/23You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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;
}