Tuesday, June 21, 2016

Why doesn't C++ have finally in try/catch

http://www.stroustrup.com/bs_faq2.html#finally

By the C++ creator himself. TLDR:

C++ has a way better solution scoping, and releasing the resources at the end of a scope. Also known as RAII.

Thursday, June 16, 2016

Latest C++ Debugging Tips and Tricks

https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/C-Plus-Plus-Debugging-Tips-and-Tricks

As of VS2015 C++ or earlier for some features:

TLDR:

  • "Auto Window" during debugging shows the results of all functions that were executed in a line that was stepped over.

So if you have a line like that:
int result = function1()->function2()->function3();

When you step over such line, VS debugger will show the result of each functionX() calls above. Thus, you don't have to guess what were the individual results.

  • Under exceptions debug window, you can search for a specific exception type (std::exception)
  • You can set a debug breakpoint with a condition.


  • CTRL-Q for quick launching windows of VS, such memory window, parallel watch, etc.
  • "Show threads in source" shows where in the source the threads are. Useful when multiple threads are running on the same code file.
  • Integrated memory profiling can take snapshots and then compare the two and show where the extra allocation(s) came from

Wednesday, June 15, 2016

SFINAE in C++ templates, what the hell is that?

A good blog on what is SFINAE

http://jguegant.github.io/blogs/tech/sfinae-introduction.html

TLDR:

A fancy way to do C++ reflection at compile time.

Skipping debugging unannoying methods in VS

https://blogs.msdn.microsoft.com/andypennell/2004/02/06/how-to-not-step-into-functions-using-the-visual-c-debugger/

TLDR:

Who wants to debug std::shared_ptr or std::unique_ptr or std::cout << for a millionth time?
Creates a .reg file with string regex to avoid it next time.

std::reference_wrapper

C++ references are nice but sometimes they are a pain to assigned them outside of a constructor. Since they can't be left uninitialized.

http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper

std::reference_wrapper comes in to help with that.