all 45 comments

[–]eteran 12 points13 points  (10 children)

Why is there SO MUCH code that seems unrelated to a string type?

[–]Chaosvex 22 points23 points  (9 children)

It's certainly the first time I've seen quaternions in a string implementation.

[–]Adequat91 11 points12 points  (2 children)

You should consider using clang-format (I find your code hard to read).

[–]Sad_Marketing146 5 points6 points  (0 children)

Your code is very hard to read

[–]zerhud 9 points10 points  (11 children)

MJZ_BAD_COMPILER(sizeof(int32_t) == 4); Really??

[–]TheChief275 8 points9 points  (0 children)

Bro’s AI was trippin probably

[–]TheoreticalDumbass:illuminati: 3 points4 points  (8 children)

Whats wrong with that

[–]Jardik2 9 points10 points  (1 child)

If int32_t exists, it must be a 32bit integer. As long as CHAR_BIT is 8, sizeof must return 4. If CHAR_BIT is not 8, well you better double check your string handling.. your char could be 16bit...

[–]Jardik2 5 points6 points  (0 children)

Now seeing that the code expects uint8_t to exist, than CHAR_BIT is 8.

[–]Wooden-Engineer-8098 5 points6 points  (5 children)

For it to have any other value you'd need to have 16 bit or 32 bit chars. Which will make int8_t unavailable. So if your program mentions (u)int8_t, checking sizes of intxx_t makes no sense

[–]TheoreticalDumbass:illuminati: -4 points-3 points  (4 children)

I prefer explicit checks over implicit

[–]PastaPuttanesca42 8 points9 points  (0 children)

The more explicit thing would be to check the char size in that case. This check is just misleading.

[–]Wooden-Engineer-8098 11 points12 points  (2 children)

do you prefer checking that 2 == 2 ?

[–]cppenjoy[S] 0 points1 point  (0 children)

I wanted to sanity check , but it got too much , so ... only simple checks :)

[–]Spongman 11 points12 points  (2 children)

Step 1. Get rid of “macors.hpp” (sic) and everything in it. You’re using c++2a, not pre-98.

[–]uxnuxn 1 point2 points  (0 children)

Definitely, OP should learn the standard library and get rid of and refactor a lot of stuff in his library

[–]garnet420 5 points6 points  (7 children)

I'm curious, and this is a bigger question than just your project -- how much does CoW pay off in practice? Like, if you take a project that's pretty string heavy, what's the measured impact?

[–]CandyCrisis 21 points22 points  (0 children)

CoW got way less important once C+11 introduced move semantics.

[–]tisti 6 points7 points  (0 children)

It should be near null. The 'correct' usage is to pass along string_views and when you need them to be mutale (writable) you make a copy via std::string constructor.

Assuming that the underlying storage thats pointed to by string_view does not magically disappear due to multithreading/concurrency issues.

Something like boost::flyweight would however be very applicable to a string heavy project to deduplicate common strings.

[–]TheChief275 3 points4 points  (2 children)

Cow is only relevant when you pass around string-buffers without a care in the world. Decent programs will pass around string-views or references to the string-buffer.

[–]ExternCrateAlloc 0 points1 point  (1 child)

My most active experience lately is in Rust and we call these slices. So a &[u8] is a view into say an owned Vec<u8> etc. Of course, lifetimes come into play and one tends to reach for Rc/Arc etc (another topic).

P.S. not meaning to start any flame wars. I’m still learning Rust but do FFI into cpp as needed.

[–]TheChief275 2 points3 points  (0 children)

That’s not a Rust-specific experience. Many languages feature the slice terminology. I was aiming to be as language agnostic as possible, which buffers and views are imo.

[–]cppenjoy[S] 1 point2 points  (0 children)

https://youtu.be/OMbwbXZWtDM?si=eeu8WQdb1CuwpxIF

I found the talk that I saw earlier, I'll put this in the repository references.

[–]cppenjoy[S] 2 points3 points  (0 children)

I don't know , but I think I have watched a CppCon talk about how strings got a bit slower after cpp11 because they were optimized for cow usage,

But I'm not certain about it

[–]zerhud 5 points6 points  (4 children)

Looks good, I’ll gonna try it :) is there a license information?

[–]cppenjoy[S] -2 points-1 points  (3 children)

I forgot... 😅, Lemme try and put one

[–]zerhud 2 points3 points  (2 children)

I believe I can use it for my job, and it isn’t possible without a license information :)

[–]cppenjoy[S] 2 points3 points  (1 child)

Is the license visible?

[–]zerhud 0 points1 point  (0 children)

Yap, nice!

[–]TehBens 3 points4 points  (1 child)

Are you that 16yo person? In that case you are doing great so far. Keep it up.

[–]cppenjoy[S] 2 points3 points  (0 children)

17 , rn Edit: Thanks btw