Comments (11)
Hi @larkwiot and @johnmcfarlane
from_chars()
is in with #400
from wide-integer.
Hopefully there's a generic way to handle both string
s and string_view
s in the same algorithm.
It might be a little trickier to wrap your head around if you're not used to dealing with iterators and templates as much as indexes and char*
s, but you may find the solution is cleaner and more satisfying. Example.
from wide-integer.
a utility function like
from_string()
is the most appealing to me personally
Hopefully there's a generic way to handle both
string
s andstring_view
s in the same algorithm.
Of course @johnmcfarlane, I can/will implement (it in a hopefully nice and non-ambiguous way) with template-iterators first
/last
. This would be, ... as usual as possible from the perspective of the STL philosophy.
from wide-integer.
Oh you know what?
A while back, I implemented something that tries as best as possible to immitate to_chars()
.
I might as well implement now for this issue something that's close to from_chars()
.
from wide-integer.
It wouldn't be a good design choice to inject a dependency on string_view
into uintwide_t
. Those ought to be two separate types. A non-member function template might be a good idea though, maybe called something like e.g. from_string
.
And as this seems to be a literal value, perhaps a UDL would work, e.g.:
constexpr static uintwide_t<65535, std::uint64_t> BIG_INT_CONSTANT {0xA0A0A0000000000000000000000_wide_integer};
from wide-integer.
any way to construct directly from a StringView?
Yes, but I agree with John (@johnmcfarlane), who indicates, ...
wouldn't be a good design choice to inject a dependency on
string_view
intouintwide_t
. Those ought to be two separate types. A non-member function template might be a good idea though, ...
There is already a constructor from const char*
, but that does not work for string-view because this constructor requires a Null-Terminated character pointer array and string-view is not Null-Terminated.
I think it owuld be best if we were to discuss either a factory-like non-member function or something like what John sketheced out above.
from wide-integer.
There is already a constructor from
const char*
Since that constructor is already there, would it be a fair compromise to add a second, default-set length parameter which could handle string-view (which is non-null-terminated).
Could this be a reasonable solution?
Cc: @larkwiot and @johnmcfarlane
from wide-integer.
Thanks for your guys' time on this!
I personally don't have a preference on the implementation of this, I just like the library and wanted to have some global constants. Of the solutions mentioned so far, a utility function like from_string()
is the most appealing to me personally, but any way this functionality could be implemented is a win for me.
from wide-integer.
a utility function like
from_string()
is the most appealing to me personally
I appreciate this. There is, however, a special case to handle. When dealing with string_view
, there is no guarantee that the associated char
-pointer array is NULL
-terminated.
Personally, I do not like creating an std::string
(i.e., from a string_view
) for the sole purpose of using its c_str()
method to obtain a NULL
-terminated string. So I think a few overloads of a potential from_string()
method would also be useful.
Let me put together a draft and present it in a future PR.
from wide-integer.
Note to self: Implementation detail, ... the proposed from_chars
is very similar to the existing rd_string
. Adapt accordingly with probably minimal effort.
from wide-integer.
See also #400
from wide-integer.
Related Issues (20)
- equivalent to mp::import_bits, mp::export_bits? HOT 5
- Upgrade docs to use Markdown's own LaTeX interpreter
- Handle Ubuntu 18.04 Deprecation on GHA
- about import_bits/export_bits HOT 9
- Replace (soon to be deprectated) LGTM with GitHub's CodeQL
- Cannot use integers in template parameters due to private data members. HOT 6
- Possible bug with <?> HOT 2
- Support signed/unsigned floored division (like Python // operator or divmod) HOT 3
- Adapt for GCC 13 HOT 2
- Halt early in a n_by_n multiplication loop if numbers are small enough HOT 16
- valgrind investigations HOT 6
- Repair GCD reduction which is broken for certain small values
- Refactoring has lead to slight performance drop and needs repair HOT 2
- Add cygwin run in CI HOT 2
- Update and modernize CI HOT 2
- Client request C++14 constexpr-ness HOT 1
- Clean up constexpr-ness HOT 1
- Coverity scan for `uintwide_t`, example and test software HOT 1
- Repair cygwin in CI and upgrade all CI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wide-integer.