« first day (1530 days earlier)      last day (1314 days later) » 

6:20 AM
Hi all
Do I understand correctly that there is no way to specify locale for stod/stof/strtod/strtof other than std::setlocale()?
And that setting a locale on a stream object does not affect the stod that you call on string extracted from that stream?
 
6:39 AM
@iksemyonov yes
 
Sol if I want to reliably parse text files containing numeric data, my best bet is to use a stringstream and imbue that with the C locale?
 
parsing text with locales seems dangerous to begin with
 
The problem is that some target environments to run this software are Windows machines with non English locales set
@PeterT rephrase?
 
that's why stuff like std::from_chars was invented
parsing text from a common file format requires a common locale
 
right, except that gcc9 doesn't have from-chars for floats yet
 
6:42 AM
the C model with the locale being set on the local machine is a very old relic from a time where mainframes were the "normal" computers and files weren't exchanged on the internet
there's other parsing libraries
 
I've tested that, only integers are supported
well I understand, however my requirement is to use nothing but the *standard library unless hard pressed to do so
I could use boost lexical cast e.g., I guess that's locale independent
 
 
3 hours later…
9:51 AM
Let x be type mpz_class. I want to do switch(x % 10){...} but this won't compile because switch quantity not an integer. What's best solution? Should I cast the result to int?
 
nwp
If casting is the proper way to get an int out of an mpz_class then yes.
Though I wonder why that operator doesn't return an int int the first place. It seems safe to do.
Maybe because of precision issues in further computations.
 
10:12 AM
@nwp how do I cast? I try
` mpz_class test(5000);
unsigned long test2 = (test%10).get_ui();` and get `'class __gmp_expr<__mpz_struct [1], __gmp_binary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, long int, __gmp_binary_modulus> >' has no member named 'get_ui'`
Also static_cast<unsigned long>(test); doesn't work.
 
nwp
Hmm, it's an expression template. mpz_class{test % 10}.get_ui() should do what you want, but maybe there is a better way.
 
It needs unsigned long test2 = mpz_class(test%10).get_ui(); but I don't know why the new deceleration is necessary
 
nwp
Maybe get_ui doesn't return an unsigned int after all, but a class that is convertible to one. You should be able to CTRL+Click on .get_ui to check.
The reason is that sometimes people do (a + b) % 2 and if you execute it naively you do a pointless computation of a + b and then only look at the last bit. You really want to know that only the last bit is relevant when doing a + b and the way to do that is to return some template placeholder when doing a + b and have % 2 add to that template placeholder. In the end when you evaluate the placeholder it has full information and can only compute that last bit.
The downside is that auto result = a + b; stores a template thing instead of the result and (a + b).get_ui() doesn't work anymore because they forgot to support .get_ui on the template thing.
 
 
7 hours later…
5:41 PM
Hey, just a quick question. How would I pass a run-time variable as a template parameter **assuming I know this value is always say 1, 2, or 3 or some finite list.

At the moment I have some ugly switch statement like:
switch(value){
case 1:
my_func<1>();
break;
/// etc
}
i.e. is there some way of explicitly instantiating all instances of the templated function that can happen from my pre-defined list
and then calling the right one at run-time
 
3 messages moved from Lounge<C++>
@iyop45 doing exactly that?
you just do an explict instantiation but why are you trying to do a template parameter at runtime?
 
6:08 PM
yea I was just wondering if there was a neater way than just explicitly making a function pointer lookup table. Like maybe with some modern c++ features I don't know about :p
 

« first day (1530 days earlier)      last day (1314 days later) »