C++
Use AddressSanitizer.
C++23
import std;
int main()
{
std::println("Hello, world!");
}
C++23's New Fold Algorithms - C++ Team Blog
Courses
- C++ базовый курс, MIPT - YouTube
- С++ магистерский курс, МФТИ, 2022-23 - YouTube
- CppCon 2021 - Back To Basics - YouTube
- SENG 475 and ECE 596C — Advanced Programming Techniques for Robust Efficient Computing (With C++)
- GitHub - facontidavide/CPP_Optimizations_Diary: Tips and tricks to optimize your C++ code
- GitHub - banach-space/cpp-tutor: Code examples for tutoring modern C++
- GitHub - dendibakh/perf-ninja: This is an online course where you can learn and master the skill of low-level performance analysis and tuning.
Great talks
- CppCon 2017: Louis Dionne “Runtime Polymorphism: Back to the Basics” - YouTube
- CppCon 2019: Louis Dionne “The C++ ABI From the Ground Up” - YouTube
Links
- Learn C++
- CppNow - YouTube
- GitHub - cpp-best-practices/cppbestpractices: Collaborative Collection of C++ Best Practices – Jason Turner's collection of C++ Best Practices resources
- C++ Core Guidelines – guidelines edited by Bjarne Stroustrup and Herb Sutter
- Cpp-Lang.net: all-in-one website about C++
- Compiler Options Hardening Guide for C and C++ | OpenSSF Best Practices Working Group
- All C++20 core language features with examples | Oleksandr Koval’s blog
- C++ Insights
Snippets
For loop with index
std::vector<std::string> items { "a", "b", "c" };
for (size_t index = 0; const auto &item : items) {
std::cout << item << " at index " << index << std::endl;
index += 1;
}
Functional vector map
std::vector<int> numbers { 1, 2, 3 };
std::vector<std::string> strings;
std::transform(
numbers.cbegin(), numbers.cend(), std::back_inserter(strings),
[](const auto &n) { return "Number " + std::to_string(n * 10); });
See ranges as well.
Dealing with smart pointers
#include <memory>
class Person {};
class Wrapper {
public:
explicit Wrapper(Person *person) : _person(person) {}
private:
Person *_person;
};
class RefWrapper {
public:
explicit RefWrapper(Person &person) : _person(person) {}
private:
// storing references prevents copying
Person &_person;
};
void handle_person(const Person &person) {}
int main() {
std::unique_ptr<Person> person = std::make_unique<Person>();
Wrapper wrapper{person.get()};
RefWrapper refWrapper{*person};
handle_person(*person);
}
Common mistakes
- Vector reallocation on resize will invalidate iterators
Tools
- include-what-you-use - A tool for use with clang to analyze #includes in C and C++ source files
- GitHub - doctest/doctest: The fastest feature-rich C++11/14/17/20/23 single-header testing framework