cpp_tutorials icon indicating copy to clipboard operation
cpp_tutorials copied to clipboard

This repository contains my C++ snippets code on C++ concepts/ idioms, optimized C++, modern C++ and advance C++

C++

Build status build workflow alt text

This repository contains my C++ snippets code on C++ concepts/ idioms, optimized C++, modern C++ and advance C++. I have included snippets and samples code for using third party libs for parsing CSV, YAML and JASON files. Example of code benchmarking with Google Benchmark is available. There is also a tutorial on using CMake for building and exporting your project.

Building and Installation

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

How to build on your machine

configure it:

cmake -G "Ninja Multi-Config"  -S . -B build

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

1. Building the Image

There is docker file for this project where contains all dependencies and you build the image with :

docker build -t cpp_tutorials .

2. Creating the container

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

3. Starting an existing container

If you have already created a container from the docker image, you can start it with:

docker start -i cpp_container

4. Removing unnecessary images and containers

You can remove unnecessary images and containers by:

docker image prune -a

docker container prune

GUI application with docker

  1. 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

  1. 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

C++ Tutorials

  • 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
  • Bitset, Bit field, Bitwise Operations
  • Callbacks
  • Callable Objects, std::function, std::bind, Lambda
  • Clock, Date, Time
  • Conditional Compilation From CMakeLists
  • Containers
    • vector
    • lists
    • C arrays, std::array, span
    • set, map, pair, tuple, tie, unordered_map, multimap, unordered_set, multiset
    • stack, queue, priority_queue, deque
  • Const, Constexpr and Mutable
  • Immutable Objects
  • Data Types, Numerical Limits, Machine Epsilon, Precision
  • Data Types Conversions, Casting
  • Decay
  • Dynamic Memory Allocation in C
  • Enum
  • Error Handling
  • Exception Handling, noexcept
  • Extern Variables, Extern Functions
  • 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
  • Invoke
  • Iterator, for_each loop, range-for loop, Loop optimization
  • 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 ...
  • 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
  • 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
  • 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

Advance C++ Concepts and Idioms

  • 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)

Optimizing C++

Data File Storage Parsing

  • CSV
  • YAML
  • JASON
  • XML

Code Benchmarking

  • Google Benchmark

C++ Coding Standards and Style Guide

C++ Package Manager