xo-flatstring: + __int128 printer

This commit is contained in:
Roland Conybeare 2024-04-28 14:44:35 -04:00
commit 8afe90afd6
2 changed files with 51 additions and 0 deletions

View file

@ -0,0 +1,31 @@
/** @file int128_iostream.hpp
*
* Author: Roland Conybeare
**/
#pragma once
#include "flatstring.hpp"
#include <ostream>
namespace std {
/* print a 128-bit integer */
inline std::ostream &
operator<< (std::ostream & os, __int128 x) {
os << xo::flatstring<48>::from_int(x);
return os;
}
}
#ifdef NOT_USING
namespace xo {
/* print a 128-bit integer */
inline std::ostream &
operator<< (std::ostream & os, __int128 x) {
os << xo::flatstring<48>::from_int(x);
return os;
}
}
#endif
/** end int128_iostream.hpp **/

View file

@ -1,6 +1,7 @@
/** @file flatstring.utest.cpp **/
#include "xo/flatstring/flatstring.hpp"
#include "xo/flatstring/int128_iostream.hpp"
#include "xo/indentlog/scope.hpp"
#include "xo/indentlog/print/tag.hpp"
#include "xo/indentlog/print/hex.hpp"
@ -419,6 +420,25 @@ namespace xo {
} /*TEST_CASE(flatstring)*/
TEST_CASE("flatstring_int128", "[flatstring]") {
//constexpr bool c_debug_flag = false;
// can get bits from /dev/random by uncommenting the 2nd line below
//uint64_t seed = xxx;
//rng::Seed<xoshio256ss> seed;
//auto rng = xo::rng::xoshiro256ss(seed);
//scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.flatstring_int128"));
//log && log("(A)", xtag("foo", foo));
__int128_t x = 65536UL*65536UL*65536UL*65536UL*65536UL;
stringstream ss;
ss << x;
} /*TEST_CASE(flatstring_int128)*/
} /*namespace ut*/
} /*namespace xo*/