Does C++ support ‘finally’ blocks? (And what’s this ‘RAII’ I keep hearing about?)
Does C++ support ‘finally‘ blocks? What is the RAII idiom? What is the difference between C++’s RAII idiom and C#’s ‘using’ statement? 16 Answers 16
Does C++ support ‘finally‘ blocks? What is the RAII idiom? What is the difference between C++’s RAII idiom and C#’s ‘using’ statement? 16 Answers 16
P0137 introduces the function template std::launder and makes many, many changes to the standard in the sections concerning unions, lifetime, and pointers. What is the problem this paper is solving? What are the changes to the language that I have to be aware of? And what are we laundering? 3 Answers 3
I started studying smart pointers of C++11 and I don’t see any useful use of std::weak_ptr. Can someone tell me when std::weak_ptr is useful/necessary? 15 Answers 15
I often hear that when compiling C and C++ programs I should “always enable compiler warnings”. Why is this necessary? How do I do that? Sometimes I also hear that I should “treat warnings as errors”. Should I? How do I do that? 20 Answers 20
The std::sort algorithm (and its cousins std::partial_sort and std::nth_element) from the C++ Standard Library is in most implementations a complicated and hybrid amalgamation of more elementary sorting algorithms, such as selection sort, insertion sort, quick sort, merge sort, or heap sort. There are many questions here and on sister sites such as https://codereview.stackexchange.com/ related to … Read more
Recently I’ve gotten suggestions to use span<T>‘s in my code, or have seen some answers here on the site which use span‘s – supposedly some kind of container. But – I can’t find anything like that in the C++17 standard library. So what is this mysterious span<T>, and why (or when) is it a good … Read more
I have heard that C++ class member function templates can’t be virtual. Is this true? If they can be virtual, what is an example of a scenario in which one would use such a function? 15 Answers 15
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 4 years ago. Improve this question I have XML documents that I need to parse and/or I need to build XML documents and write them … Read more
I posted a question with my code whose only #include directive was the following: #include <bits/stdc++.h> My teacher told me to do this, but in the comments section I was informed that I shouldn’t. Why? 8 Answers 8
This is a little subjective I think; I’m not sure if the opinion will be unanimous (I’ve seen a lot of code snippets where references are returned). According to a comment toward this question I just asked, regarding initializing references, returning a reference can be evil because, [as I understand] it makes it easier to … Read more