C++ Unleashed: From Zero to Hero
Welcome to C++ Unleashed: From Zero to Hero, a comprehensive and modern tutorial crafted to guide you from the fundamentals to the advanced intricacies of C++ programming. Inspired by the depth and clarity of The Rust Programming Language, this tutorial strives to incorporate the most current features and best practices in the C++ ecosystem. Whether you’re a novice eager to learn C++ from scratch or an experienced developer aiming to refine your skills, this guide offers valuable insights, practical examples, and up-to-date content to accelerate your journey.
Please note that while every effort has been made to ensure accuracy and completeness, this tutorial is a work in progress. We encourage readers to actively participate by identifying and reporting any errors or areas for improvement. Your feedback is invaluable in helping us create the most effective and reliable learning resource possible.
Table of Contents
-
- What is C++?
- Why Choose C++?
- What is xmake?
- What You’ll Learn
-
- Environment Setup
- Your First Program: Hello, World!
- Variables and Data Types
- Comments in C++
-
- Conditional Statements (
if
,switch
) - Loops (
for
,while
,do-while
) - Jump Statements (
break
,continue
,return
,goto
)
- Conditional Statements (
-
- Function Definition and Calls
- Parameter Passing
- Return Values
- Default Arguments
- Function Overloading
- Recursive Functions
- Lambda Expressions
-
- Arrays
- Limitations of C-Style Arrays
std::array
- C-Style Strings
- The
std::string
Class - String Operations
- Converting Between Strings and Numbers
-
- Basics of Pointers
- References and Their Uses
- Smart Pointers (
unique_ptr
,shared_ptr
,weak_ptr
)
-
- Classes and Objects
- Constructors and Destructors
- Copy and Move Semantics
- Inheritance and Polymorphism
- Operator Overloading
- Union and Struct as Special Classes
- Type Conversions (
static_cast
,dynamic_cast
,const_cast
,reinterpret_cast
) - Variable Modifiers (
const
,static
,mutable
,volatile
) - Virtual Functions and Abstract Classes
Templates and Generic Programming
- Function Templates
- Class Templates
- Template Specialization
- Variadic Templates
- Concepts (C++20)
-
- Auto Type Deduction (
auto
) - Range-Based For Loops
- Type Aliases (
using
) constexpr
,consteval
, andconstinit
decltype
std::variant
andstd::optional
nullptr
- Auto Type Deduction (
Standard Template Library (STL)
- Containers (
vector
,list
,map
, etc.) - Algorithms and Iterators
- Function Objects (Functors)
- Custom Containers
- Containers (
-
- The Concept of Exceptions
try
,catch
,throw
- Custom Exceptions
- Best Practices for Error Handling
Concurrency and Multithreading
- Introduction to Concurrency
- Threads and
std::thread
- Mutexes and Locks (
std::mutex
,std::lock_guard
) - Condition Variables (
std::condition_variable
) - Atomic Operations (
std::atomic
) - Futures and Promises (
std::future
,std::promise
) - Asynchronous Programming (
std::async
)
-
- Template Metaprogramming
- Type Traits and
std::type_traits
- SFINAE and
std::enable_if
- CRTP (Curiously Recurring Template Pattern)
- Variadic Templates and Parameter Packs
-
- Modules
- Concepts
- Ranges Library
- Coroutines
- Three-Way Comparison Operator (
<=>
) std::span
and Other New STL Components
-
- Filesystem Library (
std::filesystem
) - File Operations and Path Manipulation
- Filesystem Library (
Best Practices and Design Patterns
- Modern C++ Idioms
- RAII (Resource Acquisition Is Initialization)
- Design Patterns in C++ (Singleton, Factory, Observer, etc.)
- Code Optimization Techniques
- Writing Efficient and Maintainable Code
Testing, Debugging, and Building
- Unit Testing Without External Libraries
- Test-Driven Development (TDD)
- Debugging Tools and Techniques (GDB, Valgrind)
- Profiling and Performance Analysis
- Advanced xmake Usage
- Continuous Integration and Deployment
-
- Creating the
xmake.lua
File - Building and Managing Dependencies
- Custom Build Configurations
- Packaging and Distribution
- Creating the
-
- Project Ideas (Command-Line Tools, Games, Libraries)
- Implementing Projects
- Managing Larger Codebases
- Documenting and Sharing Your Work
-
- Key Takeaways
- Best Practices in C++
- Recommended Resources and Learning Paths
- Staying Updated with Modern C++
- Final Thoughts and Encouragement
Next chapter: Introduction