does boost::variant support 128 bit integer?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

does boost::variant support 128 bit integer?

Boost - Users mailing list
especially the gnu __int128?
Thanks,
David.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
I dont think so...
I guess int128_t under boost/multiprecision/cpp_int is the only viable option.

On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users, <[hidden email]> wrote:
especially the gnu __int128?
Thanks,
David.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 4/7/2021 2:00 PM, David Frank via Boost-users wrote:
> especially the gnu __int128?

There is no reason why it would not support __int128 if it is available.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
> I dont think so...

If it is available why do you think variant would not support it ?

> I guess int128_t under boost/multiprecision/cpp_int is the only viable
> option.
>
> On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     especially the gnu __int128?

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
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...

On Thu, 8 Apr 2021, 00:10 Edward Diener via Boost-users, <[hidden email]> wrote:
On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
> I dont think so...

If it is available why do you think variant would not support it ?

> I guess int128_t under boost/multiprecision/cpp_int is the only viable
> option.
>
> On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     especially the gnu __int128?

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
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.

>
> On Thu, 8 Apr 2021, 00:10 Edward Diener via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
>      > I dont think so...
>
>     If it is available why do you think variant would not support it ?
>
>      > I guess int128_t under boost/multiprecision/cpp_int is the only
>     viable
>      > option.
>      >
>      > On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
>      > <[hidden email] <mailto:[hidden email]>
>     <mailto:[hidden email]
>     <mailto:[hidden email]>>> wrote:
>      >
>      >     especially the gnu __int128?
>
>     _______________________________________________
>     Boost-users mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://lists.boost.org/mailman/listinfo.cgi/boost-users
>     <https://lists.boost.org/mailman/listinfo.cgi/boost-users>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
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.

On Thu, 8 Apr 2021, 04:30 Edward Diener via Boost-users, <[hidden email]> 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.

>
> On Thu, 8 Apr 2021, 00:10 Edward Diener via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
>      > I dont think so...
>
>     If it is available why do you think variant would not support it ?
>
>      > I guess int128_t under boost/multiprecision/cpp_int is the only
>     viable
>      > option.
>      >
>      > On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
>      > <[hidden email] <mailto:[hidden email]>
>     <mailto:[hidden email]
>     <mailto:[hidden email]>>> wrote:
>      >
>      >     especially the gnu __int128?
>
>     _______________________________________________
>     Boost-users mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://lists.boost.org/mailman/listinfo.cgi/boost-users
>     <https://lists.boost.org/mailman/listinfo.cgi/boost-users>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
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,
> <[hidden email] <mailto:[hidden email]>> 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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
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,
>> <[hidden email] <mailto:[hidden email]>> 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
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
But I am not even doing any kind of input or output using __int128 FOR THE VARIANT VARIABLE….

As you can see… if you choose to use int instead of __int128 for the VARIANT VARIABLE and rerun the code…. it is actually printing the value of the __int128 variable d which I have used in the code..
 So, I guess it is actually picking up my std::ostream& operator<<(std::ostream& o, const __int128& x) functionality.

On 08-Apr-2021, at 7:52 AM, Edward Diener via Boost-users <[hidden email]> wrote:

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, <[hidden email] <[hidden email]>> 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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On running the code given below which uses int for variant variable but uses __int128 for the variable d having value 12... I get the following output = 
  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<int, 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. }






On 08-Apr-2021, at 1:08 AM, Anil Muthigi <[hidden email]> 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...

On Thu, 8 Apr 2021, 00:10 Edward Diener via Boost-users, <[hidden email]> wrote:
On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
> I dont think so...

If it is available why do you think variant would not support it ?

> I guess int128_t under boost/multiprecision/cpp_int is the only viable
> option.
>
> On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     especially the gnu __int128?

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 4/7/2021 10:33 PM, Anil Muthigi via Boost-users wrote:
> But I am not even doing any kind of input or output using __int128 FOR
> THE VARIANT VARIABLE….
>
> As you can see… if you choose to use int instead of __int128 for the
> VARIANT VARIABLE and rerun the code…. it is actually printing the value
> of the __int128 variable d which I have used in the code..
>   So, I guess it is actually picking up my std::ostream&
> operator<<(std::ostream& o, const __int128& x) functionality.

I agree that variant does not support __int128. File a Issue report at
https://github.com/boostorg/variant if you wish. I am not the variant
maintainer. You may also try variant2.

>
>> On 08-Apr-2021, at 7:52 AM, Edward Diener via Boost-users
>> <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> 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,
>>>> <[hidden email] <mailto:[hidden email]>
>>>> <mailto:[hidden email]
>>>> <mailto:[hidden email]>>> 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
>>> [hidden email] <mailto:[hidden email]>
>>> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> [hidden email] <mailto:[hidden email]>
>> https://lists.boost.org/mailman/listinfo.cgi/boost-users 
>> <https://lists.boost.org/mailman/listinfo.cgi/boost-users>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
Hello Anil,


On Wed, Apr 7, 2021 at 11:43 PM Anil Muthigi via Boost-users <[hidden email]> wrote:
On running the code given below which uses int for variant variable but uses __int128 for the variable d having value 12... I get the following output =

You must define your operator<< in namespace std so it can be picked by ADL.

Kind regards,

PS: Do not use images to show code. Just write them in your email body.
[snip - images]

--
Felipe Magno de Almeida
Owner @ Expertise Solutions
www: https://expertise.dev
phone: +55 48 9 9681.0157
LinkedIn: in/felipealmeida

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
On 4/8/2021 2:16 PM, Felipe Magno de Almeida via Boost-users wrote:

> Hello Anil,
>
>
> On Wed, Apr 7, 2021 at 11:43 PM Anil Muthigi via Boost-users
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     On running the code given below which uses int for variant variable
>     but uses __int128 for the variable d having value 12... I get the
>     following output =
>
>
> You must define your operator<< in namespace std so it can be picked by ADL.

If you just have:

#include <boost/variant.hpp>
#include <string>

boost::variant<__int128, char, std::string> v;
v = 56;

This produces an error:

..\..\../boost/variant/variant.hpp:1578:38: error: call of overloaded
'initialize(void*, boost::move_detail::remove_reference<int&>::type)' is
ambiguous


>
> Kind regards,
>
> PS: Do not use images to show code. Just write them in your email body.
> [snip - images]
>
> --
> Felipe Magno de Almeida
> Owner @ Expertise Solutions
> www: https://expertise.dev <https://expertise.dev>
> phone: +55 48 9 9681.0157
> LinkedIn: in/felipealmeida
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
On 9/04/2021 9:45 am, Edward Diener wrote:

> If you just have:
>
> #include <boost/variant.hpp>
> #include <string>
>
> boost::variant<__int128, char, std::string> v;
> v = 56;
>
> This produces an error:
>
> ..\..\../boost/variant/variant.hpp:1578:38: error: call of overloaded
> 'initialize(void*, boost::move_detail::remove_reference<int&>::type)' is
> ambiguous

To resolve that, use static_cast<__int128>(56) instead, or assign an
__int128 variable instead of an integer constant.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 08.04.21 23:45, Edward Diener via Boost-users wrote:

> If you just have:
>
> #include <boost/variant.hpp>
> #include <string>
>
> boost::variant<__int128, char, std::string> v;
> v = 56;
>
> This produces an error:
>
> ..\..\../boost/variant/variant.hpp:1578:38: error: call of overloaded
> 'initialize(void*, boost::move_detail::remove_reference<int&>::type)' is
> ambiguous

That's because it /is/ ambiguous.  The compiler does not know if you
want to set the variant to a '__int128' or to a 'char'.  You get the
same error message if you substitute 'long' for '__int128'.


--
Rainer Deyke ([hidden email])


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: does boost::variant support 128 bit integer?

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
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...

As others have pointed out, the correct code is:

#include <boost/variant.hpp>
#include <string>
#include <iostream>

namespace std
{

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');
     }

}

int main()
{

boost::variant<__int128, char, std::string> v;
v = static_cast<__int128>(56);
v = 'Y';
__int128 d=12;
std::cout << d << '\n';
std::cout << v << '\n';
v = "Yashaswi raj";
std::cout << v << '\n';
return 0;
}


So __int128 does indeed work with variant, as I originally surmised.

>
> On Thu, 8 Apr 2021, 00:10 Edward Diener via Boost-users,
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     On 4/7/2021 2:15 PM, Anil Muthigi via Boost-users wrote:
>      > I dont think so...
>
>     If it is available why do you think variant would not support it ?
>
>      > I guess int128_t under boost/multiprecision/cpp_int is the only
>     viable
>      > option.
>      >
>      > On Wed, 7 Apr 2021, 11:39 pm David Frank via Boost-users,
>      > <[hidden email] <mailto:[hidden email]>
>     <mailto:[hidden email]
>     <mailto:[hidden email]>>> wrote:
>      >
>      >     especially the gnu __int128?

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users