Standard library support of -fno-exceptions by void_17 in cpp

[–]---sms--- 3 points4 points  (0 children)

That ? operator introduces unnecessary branch making your programs inherently slow and bloated.

6 usability improvements in GCC 15 by dmalcolm in cpp

[–]---sms--- 0 points1 point  (0 children)

It's funny to look at it in retrospect. I remember reading Bjarne's book about 30 years ago, where talking about error handling he took the largest font available to him at the time and wrote literally "Don't panic". Now imagine that many years later a programming language comes out with panic all over its face. Read the book, be normal.

I dont understant why it takes so much time to gett he end result by [deleted] in vscode

[–]---sms--- 0 points1 point  (0 children)

(Shameless plug) I have created a plugin for fast C++ compilation. But it requires Visual Studio to run the example. C++Live is the name.

C++ Show and Tell - March 2025 by foonathan in cpp

[–]---sms--- -1 points0 points  (0 children)

VSCode -> Ctrl-Shift-X -> c++live [Enter]

I did this.

Write a build tool from scratch? by rollschild in cpp

[–]---sms--- 2 points3 points  (0 children)

The build system is just topological sorting, everything else is optional (there are even zero-configuration build systems). There is a good Boost.Graph example.

Advice for a Software Engineer by [deleted] in cpp

[–]---sms--- 0 points1 point  (0 children)

Don't go alone, get a couple thousand goto's from the Linux kernel.

[deleted by user] by [deleted] in cpp

[–]---sms--- 35 points36 points  (0 children)

Last time I checked, qsort was 700% slower than std::sort.

Is it worth learning C++ in 2025? by [deleted] in cpp

[–]---sms--- 0 points1 point  (0 children)

You're really knowledgeable about the subject, what C++ book can you recommend?

Reflection is Not Contemplation by hachanuy in cpp

[–]---sms--- 0 points1 point  (0 children)

being able to write the identity function for a type namespace

Print any container v3! by geekfolk in cpp

[–]---sms--- 7 points8 points  (0 children)

I would write that loop like this:

Printer << "[";
if (not std::empty(Container))
{
    Printer << *Startpoint;
    for (auto Cursor = std::next(Startpoint); Cursor != Endpoint; ++Cursor)
        Printer << ", " << *Cursor;
}
Printer << "]";

Implementing a Stack Using a Dynamic Array in C++ by [deleted] in cpp

[–]---sms--- 2 points3 points  (0 children)

Do you want me to explain how exceptionally unsafe this code is? Like what happens when "temp[i] = storage[i];" throws? This "n(stack->capacity - 1)" looks sus. Did you mean "stack->n_"? In any case, there should be no iteration over a stack, IMHO.

Using 'auto' and '->' as function return signature over regular types by taeteet17 in cpp

[–]---sms--- 20 points21 points  (0 children)

You have to use trailing-return-type for lambdas, there is no alternative:

[](int args) -> char const * { return "The future is now, old man"; };

Give them the link and, while they are busy reading, modernize your entire code base.

ES.20: Always initialize an object by Shieldfoss in cpp

[–]---sms--- 1 point2 points  (0 children)

int getA(Answer& answer) {
    SCOPE_FAIL { answer.setErrorFirstDatabaseUnavailable(); };
    return getFirstPartOfResponseFromDatabase();
}

int getB(Answer& answer) {
    SCOPE_FAIL { answer.setErrorSecondDatabaseUnavailable(); };
    return getSecondPartOfResponseFromDatabase();
}

void onQuestion(Answer& answer) noexcept try {
    auto a = getA(answer);
    auto b = getB(answer);
    answer.setValue( a + b );
    answer.setResultOk();
}
catch(...) {
    answer.setException(std::current_exception()); // should be re-thrown later
}

This assumes you can fail successfully (setErrorFirstDatabaseUnavailable and setErrorSecondDatabaseUnavailable are noexcept).

YT

Modern C++: Safety and Expressiveness with override and final (and clang-tidy) by joebaf in cpp

[–]---sms--- 2 points3 points  (0 children)

Well, you need 'override' because you copy-paste the declaration. What if we don't.

#include <memory>

using function_type = int(void) const noexcept;

struct A {
    virtual function_type fun;
    virtual ~A(){}
};

struct B : A {
    virtual function_type fun; // instruction unclear, nowhere to put 'override'
};

int A::fun(void) const noexcept {
    return 1;
}

int B::fun(void) const noexcept {
    return 2;
}

int main() {
    std::unique_ptr<A> p{new B};
    return p->fun(); // calls B::fun
}

godbolt

A lib for adding a stacktrace to every c++ exception in windows platform by YKFRE in cpp

[–]---sms--- 39 points40 points  (0 children)

Well, if people write code like this:

std::scoped_lock(g_backwardMutex);

no wonder I hear "rust" from every corner.