|
Boost Users : |
From: Edward Diener (eldiener_at_[hidden])
Date: 2021-04-08 02:22:07
On 4/7/2021 9:58 PM, Edward Diener via Boost-users wrote:
> 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.
Apologies ! It looks as if the variant i/o is simply not picking up your
std::ostream& operator<<(std::ostream& o, const __int128& x)
functionality. I tried putting your functionality in namespace boost but
it still did not pick it up.
>
>>
>> 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 mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
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