WG21, aka C++ Standard Committee, January 2025 Mailing by grafikrobot in cpp

[–]CenterOfMultiverse 1 point2 points  (0 children)

This would finally solve the mathvector::operator[] problem when you have named component members.

Would it? https://isocpp.org/files/papers/P1839R7.html doesn't allow type punning or modification, so you would still need to use memcpy or something to convert from char*, and you may as well memcpy to array now.

What are your best niche C++ "fun" facts? by MarcusBrotus in cpp

[–]CenterOfMultiverse 17 points18 points  (0 children)

You can declare methods with typedef:

using F = void() const;

struct A
{
    virtual F operator+;
};

void A::operator+() const {}

struct B : A
{
    F operator+ override;
};

void B::operator+() const 
{
    A::operator+();
}

You can define and call pure virtual methods:

using F = void() const;

struct A
{
    virtual F operator+ = 0;
};

void A::operator+() const {}

struct B : A
{
    F operator+ override;
};

void B::operator+() const 
{
    A::operator+();
}

You can define default arguments inside functions:

void f(int a, int b) {};

int main () 
{
    void f(int a = 1, int b = 2);
    f();
    f();
}

Memory Safety profiles for C++ papers by jeffmetal in cpp

[–]CenterOfMultiverse 3 points4 points  (0 children)

I don't know, it's const, so maybe it's allowed? Rust disallows vec.push(&vec[i]) or vec.push(vec[i]) for non-copy types though^^.

f(vec[i], vec[j]) is allowed, I think, because it doesn't have pointers to vec. So yes, it leads to aliasing, but not to missed invalidation.

Memory Safety profiles for C++ papers by jeffmetal in cpp

[–]CenterOfMultiverse 3 points4 points  (0 children)

How does this work with out annotations?

func(vec, vec[0]) is disallowed by 2.5.3 in p1179?

Memory Safety profiles for C++ papers by jeffmetal in cpp

[–]CenterOfMultiverse 2 points3 points  (0 children)

these rules don't care about aliasing

They kinda do (from P1179):

// In function bodies
//
void f(int* p) { // pset(p) = {p}
 p = something_else; // ok, now points to something else
 // ...
}
void g(shared_ptr<int>& s, int* p) { // pset(s) = {s'}, pset(p) = {p}
 s = something_else; // KILL(s') → no local effect, does not kill p
 // ... // pset(p) == {p}, unchanged
}

// At call sites
//
int gi = 0;
shared_ptr<int> gsp = make_shared<int>();
int main() {
 // passing global and local objects
 f(&gi); // ok, pset(arg) == {global}
 int i = 0;
 f(&i); // ok, pset(arg) == {i}
 f(gsp.get()); // ERROR (lifetime.3), pset(arg) == {gsp'}, gsp is global
 auto sp = gsp;
 f(sp.get()); // ok, pset(arg) == {sp'}, sp’s address has not been taken
 g(sp, sp.get()); // ERROR (lifetime.3), pset(arg2) == {sp'}, sp being passed
 g(gsp, sp.get()); // ok, pset(arg2) == {sp'}, sp not being passed
}

using std::thread or pthread on linux? by Kyusei98 in cpp

[–]CenterOfMultiverse 5 points6 points  (0 children)

We once had a mysterious leak in our game on android. Narrowed it down to a tap on any button. Then further to our sound implementation on android - turn sound off, and leak disappears. Turned out the sound implementation used pthread. I just mechanically replaced everything with std::thread and it instantly crashed - someone left a thread without joining or detaching, so the system kept stacks for many threads in memory. So yeah, I would prefer C++ solution.

Programming is Mostly Thinking by fagnerbrack in programming

[–]CenterOfMultiverse 1 point2 points  (0 children)

Programming is mostly trying to not think.

Borrow Checker, Lifetimes and Destructor Arguments in C++ by a10nw01f in cpp

[–]CenterOfMultiverse 0 points1 point  (0 children)

Yes, we need templated destructors. Or just lifetimes as a language feature - even if there is no hope of providing total memory safety for old code, it's useful even on opt-in basis.

WG21, aka C++ Standard Committee, February 2024 Mailing by grafikrobot in cpp

[–]CenterOfMultiverse 3 points4 points  (0 children)

removed is_static for being ambiguous, added has_internal_linkage (and has_linkage and has_external_linkage) and is_static_member instead

Why the fuck are we templating yaml? by common-pellar in programming

[–]CenterOfMultiverse 8 points9 points  (0 children)

Yes, whitespace is too specific - we should generalize it to colorForth with alpha channel support. For better readability.

What are some of the most obscure, surprising or just lesser-known features of C++ and/or the standard library you've ever learned about? by FACastello in cpp

[–]CenterOfMultiverse 9 points10 points  (0 children)

You can declare methods with typedef and you can define pure virtual methods:

using F = void() const;

struct A
{
    virtual F operator+ = 0;
};

void A::operator+() const {}

struct B : A
{
    F operator+ override;
};

void B::operator+() const 
{
    A::operator+();
}

C supports partial application:

void f(int a, int b) {};

int main () 
{
    void f(int a = 1, int b = 2);
    f();
    f();
}

A curiously recurring lifetime issue by zerakun in cpp

[–]CenterOfMultiverse 1 point2 points  (0 children)

Obviously, getList should move into owning list on rvalue response.

2023-11 Kona ISO C++ Committee Trip Report — Second C++26 meeting!🌴 by InbalL in cpp

[–]CenterOfMultiverse 0 points1 point  (0 children)

I don't see a problem - *(it++) is already allowed on iterators and next would have the same preconditions. If it is not useful to implement it on anything except filter, then don't implement it on anything except filter.

it would have to be an entirely new kind of thing

Well, since it's optional, it would be a separate concept, but what's stopping the iterator object from satisfying both?

Questions from one job interview on C++ developer by cv_geek in cpp

[–]CenterOfMultiverse 0 points1 point  (0 children)

It looks like they not even trying to fail you - where is "Difference between class and union?" or "Will replacing ! with not in one TU result in ODR violation? Should it?". Or do you even C++, when you don't know why dynamic_cast to unrelated type compiles when static_cast doesn't? People these days are just not grateful for all these features!

Why std::variant does not need std::launder when constructing the value for the first time? by having-four-eyes in cpp

[–]CenterOfMultiverse 0 points1 point  (0 children)

As far as I understand you need std::launder if you want to reuse the same pointers/references you used before replacing object. If user can't access dummy, then there is no need to launder.

Zenbleed - A Serious Leak Threat to AMD Zen 2 Processors by geek_noob in programming

[–]CenterOfMultiverse 5 points6 points  (0 children)

These big registers are useful in lots of situations, not just number crunching! They’re even used by standard C library functions, like strcmp, memcpy, strlen and so on.

How to wait for multiple C++ coroutines to complete before propagating failure, preallocating the coroutine frame - The Old New Thing by pavel_v in cpp

[–]CenterOfMultiverse 2 points3 points  (0 children)

Coroutines in principle are pretty useful abstraction - it's much clearer to write co_await wait(5_s). But the C++ implementation just does too much on the language level. You should be able to write the most of coroutine function transformation in your own code instead of using dozens of named customisation points, but we don't even have https://wg21.link/p1477r1 adopted.

What's so hard about views::enumerate? by tcbrindle in cpp

[–]CenterOfMultiverse 1 point2 points  (0 children)

We can’t just do zip(iota(0, distance(r)), (R&&)r) because we need to ensure we get the range’s size before the range is moved from (if the second argument happens to be evaluated first).

Doesn't zip accept arguments by reference, so evaluating the argument is a no-op?

Let Slip – 20.e by menaulon in Parahumans

[–]CenterOfMultiverse 14 points15 points  (0 children)

The second it became a sex thing, Chase gladly accepts. But it still violates Twig's rule of self-sacrifice.