On 4/7/2021 7:10 PM, Anil Muthigi via Boost-users wrote:
If u see my code, I have used __int128 separately for the variable d as well. If u change the variant variable' s data type from __int128 to int , it will run just fine.
The reason your code is failing is because your stream operator uses streaming and __int128 has no stream support. If you use an __int128 in a variant, but never use streaming, your code is fine. I do not know the reason why gcc and clang support __int128 but do not support the the type in streaming. Maybe you should try asking gcc about it or investigate it as a stackoverflow question. Please do not topmost.
On Thu, 8 Apr 2021, 04:30 Edward Diener via Boost-users,
mailto:boost-users@lists.boost.org> wrote: On 4/7/2021 3:38 PM, Anil Muthigi via Boost-users wrote: > I said that I am not sure if boost::variant supports __int128 because I > had difficulties in compiling this code : > > 1. > #include
> 2. > #include <string> > 3. > #include <iostream> > 4. > std::ostream& operator<<(std::ostream& o, const __int128& x) { if (x > == std::numeric_limits<__int128>::min()) return o << > "-170141183460469231731687303715884105728"; if (x < 0) return o << > "-" << -x; if (x < 10) return o << (char)(x + '0'); return o << x / > 10 << (char)(x % 10 + '0'); } > 5. > int main() > 6. > { > 7. > boost::variant<__int128, char, std::string> v; > 8. > v = 56; > 9. > v = 'Y'; > 10. > __int128 d=12; > 11. > std::cout < 12. > std::cout << v << '\n'; > 13. > v = "Yashaswi raj"; > 14. > std::cout << v << '\n'; > 15. > } > > If u replace __int128 with int in the variant variable, it seems to work > just fine... My test with gcc-10.2 and clang-linux-11.0 shows that it does not support __int128 in iostreams.