U++

May 24, 2021 at 11:44am
May 24, 2021 at 2:14pm
not yet, but anything that improves c++ string handling mess is a winner if it did nothing else at all.
May 27, 2021 at 6:49pm
Agreed. Although I have occasionally written my own small libraries for handling strings, it would be nice to have one that's already written (and is probably better than anything I could write).
May 28, 2021 at 7:18am
I never had a problem with C++ strings. Sometimes, I find myself writing code like this:

1
2
3
4
5
6
7
8
9
10
int main()
{
     std::vector<int> a;
     
     //fill "a" with random numbers...


     if(a.find(5))
          // do something
}


And then I feel sad realizing that's for strings and I need to use a whole find() function.
May 28, 2021 at 7:49am
agent max wrote:
.... it would be nice to have one that's already written (and is probably better than anything I could write).


Have you looked at any of the boost string libraries ? There are several of them.
May 28, 2021 at 9:49am
Also, since C++17 there's std::string_view which has much less baggage.

The container finds are a little easier using C++20 ranges - as the first and last iterator don't now have to be specified - just the container - although the return value still needs to be tested against .end():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <ranges>
#include <vector>
#include <iostream>

int main()
{
	std::vector<int> a;

	// Populate a

	if (std::ranges::find(a, 5) != a.end()) {
		// Found
	}
}

May 28, 2021 at 10:01am
@seeplus

Didn't know about that, thanks for the alternative.
May 28, 2021 at 1:43pm
U++

Looks like a lot of work as gone into it. Probably worth checking out. Thanks for posting.
May 29, 2021 at 12:17pm
I never had a problem with C++ strings.

the performance of number to text and text to number in the default libraries on most systems are abysmal. You don't notice a few here and there but try doing over 100 million in a loop, the try doing it yourself, you can double, triple the speed or better.

its the 'pow' problem. The library functions do too much: the string ones support 30+ formats of numeric input, your data likely has 1 format. You can exploit that, and its a huge lift. Pow thinks all exponents are floating point and does a bunch of stuff to deal with that. You can exploit that for integer powers. General purpose tools are rarely as fast as specific purpose tools. Still, which do you use more often: integer power, or GCD? which one is in the language?
Last edited on May 29, 2021 at 12:31pm
May 29, 2021 at 12:31pm
Yeah - that's why from_chars() and to_chars() were introduced with C++17.

Also have a look at https://www.fluentcpp.com/2018/07/24/how-to-convert-a-string-to-an-int-in-c/ and the follow-on article https://www.fluentcpp.com/2018/07/27/how-to-efficiently-convert-a-string-to-an-int-in-c/ . The second part has timings for the different ways for conversion.
May 29, 2021 at 9:13pm
Yeah - that's why from_chars() and to_chars() were introduced with C++17.

I searched it up, the code needed to use these functions looks abysmal, like a step backwards. Making a custom function would probably be simpler when using strings.
May 30, 2021 at 2:54am
One thing I've noticed about how the C++ standard does things is to make it consistent when it comes to iterators, etc. It might not be the simplest or easiest syntax, but it is similar no matter what part of the standard library is being referenced.

As "clunky" as the from_chars/to_chars syntax may be, it is consistent with other parts of the standard.
May 30, 2021 at 2:56am
I have never heard of U++ before, but I will definitely take a gander and see if it might be useful, as useful as the boost libraries can be.
Topic archived. No new replies allowed.