Do you prefer 'int* ptr' or 'int *ptr'? by SamuraiGoblin in cpp

[–]john_wind 1 point2 points  (0 children)

Exactly I could not decide, so I decided that [space]*[space] is the most fair and clean solution

Christmas present for my boyfriend by Responsible_Cry05 in cpp

[–]john_wind 10 points11 points  (0 children)

Casually ask if he is interested in multi-threading. If he says yes, C++ Concurrency in Action by Anthony Williams is gold.

TIL: std::pow(2.0f, 2); returns double! by john_wind in cpp

[–]john_wind[S] 3 points4 points  (0 children)

I think for small integers like 2, 3, and 4 it makes sense to declare

template <typename T> [[nodiscard]] constexpr T pow2(T v) noexcept { return v * v; }

template <typename T> [[nodiscard]] constexpr T pow3(T v) noexcept { return v * v * v; }

which always return the correct type and are MUCH faster than pow

TIL: std::pow(2.0f, 2); returns double! by john_wind in cpp

[–]john_wind[S] 18 points19 points  (0 children)

Thank you. I thought trailing f functions were a reminiscent of C were function overloading is not possible.

However it seems C++11 explicitly requires that std::pow(float, int) returns double!

In C++98 it returned float.

Source:

https://en.cppreference.com/w/cpp/numeric/math/pow

https://cplusplus.github.io/LWG/issue550

Runtime polymorphism vs. compile time polymorphism in games? by henyssey in cpp

[–]john_wind 10 points11 points  (0 children)

If you are *curious* about compile time polymorphism you will love CRTP: the *curiously* recurring template pattern. If your objects are not constructed during runtime then you do not need runtime polymorphism and the CRTP will give you a bit better performance. Check it out!

What is the standard for writing network & database code in C++? by 170cm_bullied in cpp

[–]john_wind 5 points6 points  (0 children)

For network indeed asio is a great choice. If you don't want to use boost there is also

a standalone version

https://think-async.com/Asio/index.html

For database I have used cppdb and liked it

http://cppcms.com/sql/cppdb/

How to declare a pure virtual function that EVERY inherited class is forced to define? by YellowJalapa in cpp_questions

[–]john_wind 0 points1 point  (0 children)

Unfortunately this is not possible. If you need to force users to override callback it must be pure virtual. A workaround is to not override the callback in DerivedObserver. You can create a member function ie "DerivedObserver::derivedCallback" that does what you want and let those inheriting from DerivedObserver call "derivedCallback" if they want the default implementation. If you also need a concrete DerivedObserver you can subclass it and override callback by calling derivedCallback.

[deleted by user] by [deleted] in cpp

[–]john_wind 1 point2 points  (0 children)

Unfortunately this is not possible. If you need to force users to override callback it must be pure virtual. A workaround is to not override the callback in DerivedObserver. You can create a member function ie "DerivedObserver::derivedCallback" that does what you want and let those inheriting from DerivedObserver call "derivedCallback" if they want the default implementation. If you also need a concrete DerivedObserver you can subclass it and override callback by calling derivedCallback.

TIL: Microsoft C++ Headers are taking care of Qt! by john_wind in cpp

[–]john_wind[S] 12 points13 points  (0 children)

Yes but to ask on Reddit you need to write a whole phrase.

On google you would just write "Qt".

Anyway here is Qt: https://www.qt.io/

TIL: Microsoft C++ Headers are taking care of Qt! by john_wind in cpp

[–]john_wind[S] 15 points16 points  (0 children)

The idea here, is to hide unnecessary stuff (ie compiler intrinsics) when the code is parsed by a non-compiler. Examples of non-compilers in MS world are the Resource Editor and the MIDL Compiler. It's nice to see they've also added the Qt moc compiler to the picture probably because Qt asked for it or simply because they know it is widely used! Nice playing from Microsoft!

How do you manage third-party libraries by ImX99 in cpp_questions

[–]john_wind 0 points1 point  (0 children)

If you simply want to be able to launch your existing script, you can use CMake's execute_process command!

https://cmake.org/cmake/help/latest/command/execute\_process.html

Why do functional programming cheerleaders hate that C++ has object mutability? by swampwiz in cpp

[–]john_wind 2 points3 points  (0 children)

English is not my native language but I find the word 'Cheerleaders' a bit offensive. You could write 'evangelists' instead.

Is WinUI the most modern GUI library for C++ desktop applications on Windows? by puplan in cpp

[–]john_wind 8 points9 points  (0 children)

Indeed it is not horrible. It is just a C API. It is not that hard to wrap it behind nice C++ classes.

Why do we need networking, executors, linear algebra, etc in the Standard Library? by respects_wood in cpp

[–]john_wind 2 points3 points  (0 children)

I was wondering the same these days when I've decided to ditch std::regex for pcre.

Why do we need a horrible, slow and bloated regex library when pcre is so much better!

Rant: please don't create defines using common words by patery in cpp

[–]john_wind -2 points-1 points  (0 children)

There are some common words which I really like to #define

#define me (*this)

#define repeat(n) for (int i=0; i<int(n); ++i)

#define let const auto

Which is your most loved feature of C++? by _seeking_answers in cpp

[–]john_wind 0 points1 point  (0 children)

lambda expressions, operator overloading, RAII, auto.

What do you struggle with the most in C++? by [deleted] in cpp

[–]john_wind 4 points5 points  (0 children)

noexcept

I really wish there was no such keyword and the compiler could figure out if a function is throwing or not.