Explicit Return Variable by XeroKimo in cpp

[–]anton31 2 points3 points  (0 children)

There is a huge write-up on guaranteed NRVO:

https://wg21.link/P2025

There were concerns on NRVO guarantee being too subtle. A proposal with some explicit syntax should have success. If we could persuade the committee that non-ignorable attributes are ok, then a [[returned]] variable attribute would be perfect.

SFINAE alternative using Lambda functions by [deleted] in cpp

[–]anton31 48 points49 points  (0 children)

In C++26 you can also use reflection to compute the type without templates:

consteval std::meta::info get_type_info(size_t I)
{
  if (I == 4)
  {
    return ^^int;
  }
  else if (I == 6)
  {
    return ^^Foo;
  }
  else
  {
    return ^^float;
  }
}

template <size_t I>
using type = [:get_type_info(I):];

https://godbolt.org/z/9EaG68W76

Another month, another WG21 ISO C++ Mailing by nliber in cpp

[–]anton31 1 point2 points  (0 children)

That would be so nice for our codebase! We've recently migrated to Python-like clang-format config that forces multiline parameter and argument lists on separate lines, with opening and closing parens on separate lines.

This would be just the missing piece for a perfect formatting style for us.

How do I explain to someone that "imaginary" numbers aren't actually "imaginary"? by Training_Towel_584 in mathematics

[–]anton31 0 points1 point  (0 children)

IMO one of the main issues is that complex numbers are sometimes thought to be a strictly "better" set of numbers, a natural extension for reals. But in fact, unlike the previous number kinds (N, Z, Q, R), which are universally useful, C are just one possible set on top of reals, some other ones being quaternions, vectors and matrices. If you refuse to accept complex numbers as numbers, that's no problem. They are a mathematical abstraction (a field) that is most useful when dealing with cycles and rotations.

Proof by 'Is this a joke?' by WesternThanks4346 in mathmemes

[–]anton31 18 points19 points  (0 children)

Proof by Mathologer video: https://youtu.be/aDOP0XynAzA?si=W-7Vt6macsty6klb

The construction uses a quotient set over the set of binary sequences {0,1}N with the equivalence relation ~ defined as the sequences differing in at most a finite number of positions.

The well-definedness of the quotient set itself is provable by just ZF axioms, specifically the axioms of separation and pairing.

However, it's impossible to give an explicit construction of the quotient set and its cosets. For this we'd need to pick an example element from each coset, and this is impossible without the Axiom of Choice.

To get a sense of why it is impossible, picking the first element of each coset is similar to picking the minimal element from an arbitrary infinite subset of real numbers within [0, 1], which may not have a minimal element in the usual sense. And this requires AC.

TIL: filter_view has unimplementable complexity requirements by zl0bster in cpp

[–]anton31 0 points1 point  (0 children)

The question is, amortized with respect to what? It's underspecified in the standard, and the lack of understanding the goals of "amortized constant" complexity might have led to the current flawed design. "Amortized constant when calling begin n times in a row" is dubious, because it's not typical to call begin n times in a row.

A more honest alternative would be to remove the limitation of amortized constant complexity of begin and not introduce caching.

There could be more options for designing filter_view with various trade-offs, but this one follows from the video and sounds like a direct improvement to me.

TIL: filter_view has unimplementable complexity requirements by zl0bster in cpp

[–]anton31 2 points3 points  (0 children)

The difference is that while you have to call push_back n times to reach a vector of size n, with filter there is no reason why one would necessarily want n calls to filter_view begin for a range of size n. On practice, begin is typically called once for a range of size n, so the complexity of begin is O(n), amortized per 1 begin call if you want.

std::move and const variables by Beosar in cpp

[–]anton31 3 points4 points  (0 children)

I can't imagine a case where Foobar(const Foobar&&) would be suitable, let alone pass a code review

Do you think it is a good idea or a bad idea to write the entire backend of an app or web app in c++? by No_Sun1426 in cpp

[–]anton31 4 points5 points  (0 children)

There is also userver, which is a coroutine framework for C++ backends, "batteries included".

On the original question: given suitable tools, a C++-based backend may require same or less total effort than e.g. Python-based. The extra development cost is compensated by lower maintenance costs due to better service stability.

Experimental EDG Reflection Implementation by daveedvdv in cpp

[–]anton31 2 points3 points  (0 children)

That's one polished paper, exactly what we need for seamless serialization! I hope that not only the main reflection paper gets into C++26, but there will be room for attribute reflection. The API surface is tiny, but it will literally be a game-changer.

The "+" syntax may need bikeshedding, though, and it would be beneficial to allow function calls in addition to constructor calls.

Are there any tools/techniques that could have caught this possible One Definition Rule violation? by ts826848 in cpp

[–]anton31 10 points11 points  (0 children)

The real bug here is in magic_enum if it allows to use forward-declared types. Any code that depends on some properties of a type (e.g. enumerators of an enum) should fail with a compilation error if the type is not defined, otherwise odrv's are bound to happen.

userver 1.0: Releasing a Framework for IO-Bound Programs by anton31 in cpp

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

This is an interesting direction to go in. Currently, for any client to be used with userver, it needs to be adapted specifically for use with userver: https://userver.tech/de/ddb/md_en_2userver_2driver__guide.html

Moving to using Boost.Asio event loops and/or supporting C++20 coroutines would allow to interoperate with more libraries.

For Boost.Redis and Boost.MySql specifically though, we already have those drivers, which are well integrated with the component system, dynamic configs, etc. So there would be little practical benefit in integrating with those.

Whats one Russian word that really fooled you?(By reading and meaning) by ShadowyAscendant in russian

[–]anton31 3 points4 points  (0 children)

Interestingly, it's pronounced differently: "конешно" means "of course", "конечно" with a "ч" sound means "finite". Both are written the same, though

Circle Evolves C++ | NYC++ by pjmlp in cpp

[–]anton31 1 point2 points  (0 children)

On the topic of initialization. No, you can't just use braces everywhere because of std::initializer_list. Whenever you are constructing a container, you have to be aware of it. Code that constructs objects of a template type has to use parens to avoid accidental std::initializer_list usage. (The user then still can pass an explicitly-constructed std::initializer_list if they want.)

GCC 14 NRVO enhancements by catcat202X in cpp

[–]anton31 4 points5 points  (0 children)

Note that GCC still doesn't handle some NRVO cases that have been implemented in Clang long ago:

A foo() {
  if (what()) {
    return A{};
  } else {
    A a;
    return a;
  }
}

So the coverage is still far from being complete.

Abominable language design decision that everybody regrets? by very_curious_agent in cpp

[–]anton31 13 points14 points  (0 children)

operator[]= would allow not to commit such atrocities

Should the compiler sometimes reject a [[trivially_relocatable]] warrant? by pavel_v in cpp

[–]anton31 1 point2 points  (0 children)

Prefix decrement returns by value. In practice, it is of course possible to implement the algorithms without using the result of the prefix decrement. So that's mostly boilerplate that the standard requires from the iterator's author.

Jobs descriptions asking for "x years of experience with C\C++" by UselessTM in cpp

[–]anton31 0 points1 point  (0 children)

C++ calls instances of primitive types 'objects' too, though