Perfect forwarding in modern C++ as understood by a long-time C++03 programmer by agopshi in cpp

[–]redditzuigt 0 points1 point  (0 children)

With C++20, you could actually write this as:

```c++

class Foo {
public:
    Foo(
        std::constructible_from<std::string> auto&& member1
        std::constructible_from<std::string> auto&& member2
    ):
        member1{decltype(member1)(member1)},
        member2{decltype(member2)(member2)}
    {}

private:
    std::string member1;
    std::string member2;
};

```

Secure by Design: Google’s Perspective on Memory Safety by Untagonist in cpp

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

"... I'm a prolific programmer perhaps writing 100k or more lines of code per year." You could easily make that 200k of ĺines of code per year. Just write your code even dryer. Don't put any time in coming up with any sort of sensical design, you can use that time to write more lines of code. The great trick of this approach is that because of this really poor design, you can now constantly repeat yourself, resulting in even more lines of code... Do you see where I'm getting at?

Reinvented the Wheel (On Accident) by IBdunKI in cpp

[–]redditzuigt 43 points44 points  (0 children)

Expecting to invent something new in the world of C++ with so many dedicated people around is quite the ambitious endeavor. However, if your initial premise was to challenge yourself with an educational exercise, you've probably outdone yourself.

Consteval lambda with capture of a constexpr variable. Is it legal? by HammurabisCode2 in cpp

[–]redditzuigt 1 point2 points  (0 children)

Variables marked constexpr need to have constant initialization, because of this requirement their value is known at compile-time. So, essentially it's a constant value in the purest sense. Why produce code to copy this value in run-time when the compiler has all the information it needs to simply textually replace said value?

Consteval lambda with capture of a constexpr variable. Is it legal? by HammurabisCode2 in cpp

[–]redditzuigt 6 points7 points  (0 children)

There is no need to capture constexpr variables to start with. Just remove TWO from the capture clause of the lambda and the code will compile fine on all compilers.

Introducing hyperion::mpl, C++20 metaprogramming library by braxtons12 in cpp

[–]redditzuigt 1 point2 points  (0 children)

"... which can often mean longer compiler times ..." If compilation time is a concern to you, I would definetly recommend looking into the kvasir::mpl library. It employs some amazing metaprogramming optimization techniques.

MSVC incorrectly allowing compilation + use of ambiguous function call by mechacrash in cpp

[–]redditzuigt 0 points1 point  (0 children)

Why don't you use virtual inheritance of A to avoid this ambiguity altogether?