This repository contains my C++ snippets code on C++ concepts/ idioms, optimized C++, modern C++ and advance C++. I have included snippets and sample code for using third-party libs to parse CSV, YAML, and JSON files. An example of code benchmarking with Google Benchmark is available. There is also a tutorial on using CMake to build and export your project.
if you need to update your CMake:
Navigate to CMake's official website to get the link for the latest source tarball:
./bootstrap
make -j$(nproc)
sudo make install
sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
configure it:
cmake -G "Ninja Multi-Config" -S . -B build
or specify where to install it:
cmake -G "Ninja Multi-Config" -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
build it:
cmake --build build --config Release
or
cmake --build build --config Debug
or be more specific:
cmake --build build --target all --config Release
If you prefer preset
use:
cmake --preset ninja-multi
and
cmake --build --preset ninja-multi-debug
or
cmake --build --preset ninja-multi-release
There is a docker file for this project that contains all dependencies and you build the image with:
docker build -t cpp_tutorials .
Create a container where you mount the checkout code into your container:
docker run --name <continer-name> -v <checked-out-path-on-host>:<path-in-the-container> -it <docker-image-name>
for instance:
docker run --name cpp_container -v /home/behnam/workspace/cpp_tutorials:/cpp_tutorials -it cpp_tutorials
If you have already created a container from the docker image, you can start it with:
docker start -i cpp_container
You can remove unnecessary images and containers by:
docker image prune -a
docker container prune
- You need to run:
docker run --name cpp_container -v /home/behnam/workspace/cpp_tutorials:/cpp_tutorials --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it cpp_tutorials
- On the host run the following (every time you run your container):
export containerId=$(docker ps -l -q)
xhost +local: docker inspect --format='{{ .Config.Hostname }}' $containerId
read more here
To configure VSCode to use CMake with the "Ninja Multi-Config" generator for all CMake projects, you can modify the VSCode settings. Here's how you can do it:
- Open your VSCode workspace or project.
- Press
Ctrl + ,
to open the settings, or navigate to File > Preferences > Settings. - In the settings search bar, type "cmake generator".
- Locate the "Cmake: Generator" setting.
- Click on "Edit in settings.json" or manually edit your
settings.json
file.
In your settings.json
file, add or modify the "cmake.generator"
setting to specify "Ninja Multi-Config" as the default generator for all CMake projects:
{
"cmake.generator": "Ninja Multi-Config"
}
Save the settings.json
file.
This change ensures that VSCode uses the "Ninja Multi-Config" generator by default for all CMake projects you work on in that workspace or project.
- Align
- Allocator
- Algorithms Library
- Any
- Assert
- Atomic operations and Atomic Types
- Asynchronous programming
- Attribute specifier sequence [[ attribute-list ]]
- Basic IO Operation, Streams, Reading/Writing Files, Formatting Output, cin, scanf, gets, getline, printf
- Big-endian,_Little-endian
- Bitset, Bit field, Bitwise Operations
- Callable Objects, Callbacks
- Clock, Date, Time
- Conditional Compilation From CMakeLists
- Containers
- Const, Constexpr and Mutable
- Immutable Objects
- Data Types, Numerical Limits, Machine Epsilon, Precision, std::nan
- Data Types Conversions, Casting, Type Coercion
- Decay
- Dynamic Memory Allocation in C
- Enum
- Error Handling
- Error Code
- Exception Handling, noexcept
- Extern Variables, Extern Functions
- Execution Policies
- File System
- Forking
- Forwarding Reference
- Functions, Extern Function, Function Objects, Function Pointer, Inline Functions
- Hash Functions, Hash Data Structure (Hash Table)
- Heap and Stack, Memory Layout of C Programs
- Iterator, for_each loop, range-for loop, Loop optimization
- std::less, std::greater
- std::not1 and std::unary_negate
- Lambda
- Literals
- Loading Classes Dynamically From Plugins
- Macros
- Memory Error Detection With Memory Address Sanitizer and Valgrind
- Modules
- Nested Namespaces, Unnamed/Anonymous Namespaces
- Numeral Systems in C++ Decimal, Binary, Octal, Hexadecimal
- Optional
- Parameter Pack Expansion ...
- Post-increment, Pre-increment, Unary plus
- Packaged Task
- Register Keyword
- Regex
- Pseudo-random Number Generation, Distributions
- Raw Pointers, Smart (Shared, Unique, Weak) Pointers, Reference, addressof, reference_wrapper, std::ref
- Passing/ Returning Smart Pointers To/ From Functions
- Smart Pointers Class Member
- Return, Abort, Exit, Throw, Terminate
- Scope Resolution Operator
- Scope and Life Cycle of Objects Returned by Functions
- Setting argc, argv
- Simple Command Argument Parser
- Signals
- System Call
- String C/C++, string_view, string literal, string conversion, ASCII, Unicode
- String View
- Structs
- Structured binding declaration
- Switch Case
- Template, Expression Templates
- Template argument deduction
- Ternary (One Line If)
- Temporary Objects
- Track memory allocations(overriding new operator)
- Trivial, standard-layout, Passive/ Plain old data structure (PDS)/ (POD), and literal types
- Type Traits
- Typedef, Type alias (using keyword)
- type_dispatch, integral_constant, true/false type
- Unions
- Variant
- Visit
- Variadic Templates Function
- Volatile Keyword
- C++ Classes
- Abstract Class Vs Interface
- Cast Base Class to Derived/ Derived to Base
- Class Forward Declaration
- Class Constructor Initializationlist
- Class Constructor Aggregate/ Copy/ Default/ Direct/ Value/ Uniform/ Zero Initialization, Initializer List
- Copy/ Move Constructor, rvalue, lvalue, move semantic
- Cyclic (Circular) Dependency
- Default(=default), Deleted (=delete) Constructors
- Diamond Problem Virtual Inheritance
- Explicit Constructor, Converting Constructor
- Friend Functions
- Header Guard
- Inheritance, Inheritance Prevention (final)
- Multiple Inheritance Polymorphism
- Operator Overloading
- Object Slicing
- Passing Arguments To Parent Constructor
- Private Public Protected Inheritance
- Protected Friend Class Function
- Shadowing
- Static Member Function, Static Initialization Order Fiasco
- Special Member Functions
- Virtual Function Abstract Class
- Virtual Destructor, Virtual Constructor
- Multithreading and Process
- Process, Inter Process Communication (IPC), Process Tree, Process Control Block (PCB
- Creating (Thread Callable Objects), Terminating Threads
- Over Subscription
- Differentiating Between Threads
- Sleeping Threads
- Joining/ Detaching Threads, Joinable Detachable
- Threads Yield
- Thread Synchronization
- Racing Condition
- Mutex
- Semaphor
- Thread Safe
- Dead Lock
- Lock Guard
- Scoped Lock
- Unique Lock
- Condition Variable
- Future, Promise and async
- Packaged Task
- Event handling/ Concurrency/ Thread design pattern
- Argument-dependent lookup
- Buffer overflow
- Copy and Swap
- Generating and Debugging Dump File
- Static Casting, Dynamic Casting
- Run-Time Type Information(RTTI)
- Curiously Recurring Template Pattern (CRTP)
- Copy Elision, Return value optimization (RVO, NRVO)
- Double Dispatch
- Most vexing parse
- Metaprogramming
- Pointer to implementation (PIMPL)
- Return Type Resolver
- Resource Acquisition Is Initialization (RAII)
- Rule of 5
- Substitution failure is not an error (SFINAE)
- Stack overflow
- Stack Unwinding
- Type Erasure
- Template Specialization, Tag Dispatch
- Virtual Method Table(VTABLE), Virtual Table Pointer(VPTR)
- Virtual address space
- Tricky Questions
- C++ Translation Units
- Undefined behavior, Unspecified and Implementation-Defined
- Printing List of All Included Headers
- fPIE (Position Independent Executable) and fPIC(Position Independent Code and)
- Lexical Analyzer