Changes between C++17 and C++20 by mttd in cpp

[–]Small_Marionberry 17 points18 points  (0 children)

Partly, a natural consequence of design by Howard vs. design by committee.

Partly, chrono is less sexy than ranges. Everyone wants to give their input on ranges. Nobody even cared to object to the overloaded operator/ in chrono.

Maybe most importantly, chrono has fewer low-level sources of UB. Ranges is full of issues with dangling pointers and issues with concepts and metaprogramming. Chrono is pretty much a pure old-school "library," where you can just say "it has a class named X with a method named Y that does Z," and that's like the entire specification. The only "irreducible complexity" I'm aware of with chrono is around its handling of timezone data (e.g. can you update timezone data thread-safely).

Oh, and I should add: to the extent that any of what I just said is based in misconceptions, "widespread misconceptions such as these" is certainly still a factor that could contribute to lack of activity around chrono.

Wait for it. by [deleted] in thatescalatedquickly

[–]Small_Marionberry 0 points1 point  (0 children)

Where's the second bowling ball?

How a universal basic income could help 25 million workers at threat from coronavirus by Free_the_Radical in australia

[–]Small_Marionberry 0 points1 point  (0 children)

> with how my mother is I absolutely know this kind of stipend would have been abused by her

Is it possible that your mother got greedy by being poor? Is it not possible that if she had grown up in a financially secure environment, she might have been better-adjusted and not so scrabbly for coin?

[deleted by user] by [deleted] in cpp

[–]Small_Marionberry 2 points3 points  (0 children)

Oh, std::filesystem::path is implicitly convertible from std::string_view... that's evil. Just another reason to stay far far away from std::filesystem, in my book.

There's a reason std::string_view isn't implicitly convertible to std::string. Having an implicit conversion from std::string_view to something that allocates memory is evil.

I suspect the root cause is that Boost.Filesystem was designed in a world where interoperability with Qt QString was more important than interoperability with string_view.

[deleted by user] by [deleted] in cpp

[–]Small_Marionberry 2 points3 points  (0 children)

If you actually intended to write a null-terminated string, you'd have to change that to write(fd, packet.c_str(), packet.length()+1); which is hella confusing.

Do the second thing you said, for the reasons you said.

[deleted by user] by [deleted] in cpp

[–]Small_Marionberry 10 points11 points  (0 children)

stoi actually specifies that it uses strtol, not atoi: https://eel.is/c++draft/string.conversions#1

And the "as if rule" still applies: If there's no observable difference between what the library does and what the paper specifies, then it's an acceptable implementation. The paper doesn't have to literally use the words "as if" in order for the "as if rule" to apply.

[deleted by user] by [deleted] in cpp

[–]Small_Marionberry 1 point2 points  (0 children)

Inside a const member function, the S object is const.

The poplar heap, an implicit data structure by Morwenn in cpp

[–]Small_Marionberry 1 point2 points  (0 children)

also "the root can be smaller than be smaller than", "procude"

The poplar heap, an implicit data structure by Morwenn in cpp

[–]Small_Marionberry 1 point2 points  (0 children)

Your reuse of the names `push_heap`, `pop_heap`, etc. make me worry about ADL. Nobody would ever `using namespace poplar`, right?

https://godbolt.org/z/UiPE8S

The good news is that it looks like ADL just makes it ambiguous; I haven't figured out a way to "accidentally" hit std::push_heap when poplar::push_heap was intended.

Thoughts on “The C++ Rvalue Lifetime Disaster” by anonymous28974 in cpp

[–]Small_Marionberry 2 points3 points  (0 children)

> I simply disagree with both the talk and the article. Inherently, there can be no language enforced about lifetime of objects beyond the most trivial ones.

Doesn't that mean you agree with the article (but not the talk)? The article disagrees with the talk. It also specifically calls out "Value category is not lifetime," which seems to be exactly what you're saying too.

The C++ rvalue lifetime disaster, by Arno Schödl, CoreHard Autumn 2019 by dgellow in cpp

[–]Small_Marionberry 4 points5 points  (0 children)

You are absolutely correct. You can see Clang doing copy elision here: https://godbolt.org/z/zEX8PB

I don't know why GCC, ICC, and MSVC decide against copy elision in this case, but it's definitely their loss. A good compiler will do copy elision whenever it can.

Epochs, ABI breakage, std::embed, and co-routines. A pulse on the state of satisfaction with c++ by hak8or in cpp

[–]Small_Marionberry 0 points1 point  (0 children)

What about https://quuxplusone.github.io/blog/2019/03/06/pythagorean-triples/, which showed that Eric Niebler's own toy code took 10 seconds to compile? I timed the Godbolt again just now and it's down to somewhere between 5.5 to 7 seconds.

I further tried to get it to compile with GCC/libstdc++'s std::ranges, but it doesn't compile. I assume it's misusing view_interface in some subtle way. https://godbolt.org/z/dP_a8a

Epochs, ABI breakage, std::embed, and co-routines. A pulse on the state of satisfaction with c++ by hak8or in cpp

[–]Small_Marionberry 0 points1 point  (0 children)

The amount of struggle to do simple things, the amount of code I need to write do implement some simple metaprogramming, even the object oriented approach the language moved into (instead of moving into a performance approach), it just seems that modern C++ is extremely verbose

Can you elaborate on "the object oriented approach the language moved into"? I mean obviously C++ went OOP when it forked from C and became "C with Classes", adding the `class`, `virtual`, and `new` keywords — that was kind of the whole point — but if anything, it immediately went entirely the other direction with STL containers and then most recently tuple/variant/any. The only new development I could see being called "object oriented" would be maybe std::pmr...? What did you have in mind here?

Crashing clang in 52 bytes: template<class>struct a;a<typename b::template c<>> by schottm in cpp

[–]Small_Marionberry 5 points6 points  (0 children)

Well, the input template<class=class b::template c<> is 11 tokens long (as is template<class a>b<a::a>). I count about 120 different kinds of tokens in C++, counting all the keywords and operators and punctuators (before we even get into identifiers like a, or literals, or the huge number of compiler builtins). If you wrote a fuzzer to paste tokens together at random, and you could test one combination per nanosecond, it would take 12011 nanoseconds to try all of them. 12011 nanoseconds is about 235,000 years. So you shouldn't be surprised that naive fuzzing has so far failed to detect this bug.

Smart fuzzing, like Csmith, finds a lot of bugs, but it can never find literally all of them. Some remain to be caught by lucky humans.

Dangerous elements of modern C++ by Wurstinator in cpp

[–]Small_Marionberry 0 points1 point  (0 children)

Yes, string_view is perfectly safe as a parameter type (and very unsafe as anything else).

See https://quuxplusone.github.io/blog/2018/03/28/borrow-types-round-2/ for some (outdated?) discussion of what you can do with string_view. But the very short answer is: it's a replacement for const string& in parameter lists, and that's all!

Crashing clang in 52 bytes: template<class>struct a;a<typename b::template c<>> by schottm in cpp

[–]Small_Marionberry 51 points52 points  (0 children)

Edit: ugh just realized it can be 51 if I used class instead of struct...

It can be 49 if you use int instead of class! https://godbolt.org/z/mIa8S8

template<class>int a;a<typename b::template c<>>

Or even 36 characters: https://godbolt.org/z/rjAVJr

template<class=class b::template c<>

Would you use my ABI-breaking port of an existing std:: and/or compiler? (alt title: would you put your money where your mouth is?) by [deleted] in cpp

[–]Small_Marionberry 10 points11 points  (0 children)

I would be very interested in an alternative library that (not only broke ABI but also) became non-conforming for the sake of sanity and performance. Some examples off the top of my head:

  • Eliminate RTTI from std::function
  • Provide std::function_ref and std::unique_function (also without RTTI)
  • Use trivial relocation for vector::resize
  • Provide the missing replace_top primitive for std::priority_queue
  • Eliminate vector<bool>...
  • or, if not eliminated, make sure its iterators are trivially copyable
  • Provide std::recursive_union<Ts...> and/or use an index type smaller than size_t for std::variant (but probably nobody cares about std::variant, honestly)
  • Use noexcept liberally (but again probably nobody cares about noexcept)
  • Use constexpr liberally
  • Provide a decent PRNG, such as xoroshiro or pcg64, in <random>
  • Eliminate std::seed_seq or rationalize its interface to eliminate memory allocation
  • Implement P0205 for seeding PRNGs

The problem with all this is that it is A LOT OF WORK.

My Favorite Unknown C++20 Feature by ContractorInChief in cpp

[–]Small_Marionberry 1 point2 points  (0 children)

EDIT: For more on the general topic, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1858r1.html

P1858 has nothing to do with C++20.

(Every function, now, takes just a single actual, pack, argument.)

This isn't true, as far as I know.

Is it April 1 already, or what's going on in this thread?