|
Boost Users : |
From: Edward Diener (eldiener_at_[hidden])
Date: 2021-04-08 01:58:51
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,
> <boost-users_at_[hidden] <mailto:boost-users_at_[hidden]>> 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 <boost/variant.hpp>
> >Â 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 <<d << '\n';
> > 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.
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net