Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use std::hex for my custom uint128 type?

Tags:

c++

hex

What is the correct syntax to overload (or whatever is actually is) std::hex, so that its functionality can be extended to non standard integers? i wrote this version of uint128_t

like image 556
calccrypto Avatar asked Jun 03 '11 05:06

calccrypto


1 Answers

std::hex is just a manipulator which set some of the formatting flags on the stream. You can get them using ios_base::flags() and use the result in your operator<<. You probably should also use ios_base::width and ios_base::precision.

If you want more settings than what is provided, ios_base::xalloc, ios_base::iword, ios_base::pword furnish a path to extensions for your manipulators and insertors.

like image 136
AProgrammer Avatar answered Oct 04 '22 21:10

AProgrammer