Interactive Learning: Tutorials and Workshops¶
We're thrilled to announce a major expansion of mp-units learning resources: comprehensive tutorials and hands-on workshops that make learning type-safe physical quantities and units both accessible and engaging. Whether you're taking your first steps with the library or ready to master advanced patterns, we've got you covered.
Learn by Doing: Interactive Code Examples¶
All tutorials and workshops feature embedded interactive code editors powered by Compiler Explorer, making learning truly hands-on. Each code example is a live editor that compiles and runs automatically as you type:
- ✅ Edit and see results instantly — Type code and watch it compile in real-time
- ✅ Get immediate feedback — Compiler diagnostics appear as you code
- ✅ See program output — View text output directly below the editor
- ✅ Experiment freely — Try variations without leaving the documentation
- ✅ Learn by doing — Active coding beats passive reading
No installation required. No setup overhead. Just start typing and learning.
Experience it yourself
In the tutorials, every code example appears as an embedded interactive editor. You can modify the code directly in the documentation page and see it compile and run instantly. For example, a speed calculation tutorial might show:
// ce-embed height=400 compiler=clang2110 flags="-std=c++23 -stdlib=libc++ -O3" mp-units=trunk
#include <mp-units/systems/si.h>
#include <iostream>
int main()
{
using namespace mp_units;
using namespace mp_units::si::unit_symbols;
quantity distance = 100 * m;
quantity time = 9.58 * s;
quantity speed = distance / time; // Automatically derives m/s
std::cout << "Distance: " << distance << "\n";
std::cout << "Time: " << time << "\n";
std::cout << "Speed: " << speed << "\n";
}
Just edit the numbers or units in the embedded editor, and watch the output update automatically below the code.
Why Interactive Learning Matters?¶
Traditional documentation tells you what the library does. Interactive learning shows you how to use it effectively.
Immediate Experimentation¶
Instead of reading about type safety, see it in action. Try the embedded editor above:
- Change
distanceto200 * mand watch the speed update - Try adding an invalid operation like
distance + timeand see the compiler error instantly - Experiment with different units:
distance = 100 * kmstill works perfectly
The compiler diagnostic appears immediately when you make mistakes, showing exactly why dimensions don't match. No waiting, no separate tools—just instant feedback as you learn.
Learn from Mistakes¶
Making mistakes is part of learning. With embedded interactive editors:
- Type invalid operations and see compiler errors instantly
- Read compiler diagnostics in context as you code
- Fix errors and watch the program compile successfully
- Build intuition through immediate feedback
Active Learning¶
Passive reading leads to passive retention. Active coding leads to deep understanding:
- Type the code yourself — Don't just read, write
- Experiment with variations — Change values, try different units
- Break things intentionally — Learn boundaries by testing them
- See immediate results — No compile/run cycle overhead
Getting Started¶
Ready to learn mp-units? Here's your roadmap:
For Beginners¶
- Start with Tutorials — Complete all 14 lessons (~3.5 hours)
- Try the Foundation Workshops — Practice refactoring patterns
- Explore Examples — Study complete applications
- Dive into specific topics in the User's Guide as needed
For Experienced Developers¶
Already familiar with units libraries?
- Skim Quick Start tutorials (30 min)
- Focus on Type Safety tutorials (~1 hour)
- Jump to Customization and Advanced Workshops
- Reference the Systems documentation for your domain
For Migration¶
Coming from another library?
- Read the relevant Migration Guide
- Complete the Workshop: Incremental Migration
- Reference Interoperability guides as needed
Tutorials: Your First 3 Hours with mp-units¶
Our 14 step-by-step tutorials (~3.5 hours total) take you from "Hello World" to confident mastery of core library features. Each tutorial is carefully crafted to:
- Build progressively — Each lesson builds on the previous one
- Teach by example — Learn through working code, not abstract theory
- Provide instant feedback — Interactive examples let you experiment immediately
- End with key insights — Every code example concludes with "What You Learned?" takeaways
Learning Path¶
1. Quick Start (~30 minutes)¶
Hit the ground running with immediate hands-on experience:
- Your First Quantities — Create and manipulate quantities with units
- Simple Math — Perform calculations and see dimensional analysis in action
- Building a Calculator — Assemble a real program putting concepts together
Perfect for...
Developers who want to see what mp-units can do before diving deeper.
2. Working with Units (~50 minutes)¶
Master unit conversions and value extraction:
- Unit Conversions — Convert seamlessly between compatible units
- Safe and Unsafe Conversions — Handle truncation and understand explicit conversions
- Extracting Numeric Values — Get numerical values safely when needed
Perfect for...
Anyone who needs to work with multiple unit systems or integrate with legacy APIs.
3. Type Safety (~65 minutes)¶
Experience the power of compile-time dimensional analysis:
- Compile-Time Protection — Watch the compiler prevent nonsensical operations
- Automatic Dimensional Analysis — Let the compiler compute derived units
- Quantity Specifications — Use quantity hierarchies for stronger type safety
- Generic Interfaces — Write flexible, reusable code with
QuantityOf
Perfect for...
Developers who want to eliminate runtime errors and write self-documenting code.
4. Affine Space (~55 minutes)¶
Understand the crucial distinction between points and quantities:
- Points and Quantities — Learn when to use
quantity_pointvsquantity - Point Origins — Work with multiple reference frames
- Temperature Handling — Handle absolute vs relative temperatures correctly
- Temperature Applications — Apply affine space concepts to real problems
Perfect for...
Anyone working with temperatures, timestamps, GPS coordinates, or any absolute measurements.
Workshops: 14 Hands-On Exercises¶
After completing the tutorials, level up with 14 workshops featuring challenge-driven learning. Each workshop presents real-world coding challenges that require you to apply concepts from the User's Guide to solve practical problems.
What Makes Workshops Different?¶
Workshops aren't just tutorials with exercises—they're deliberate practice for advanced patterns:
- Exercise-driven — Follow
TODO:markers to implement solutions yourself - Real-world scenarios — Work with production-like code, not toy examples
- Progressive complexity — Start with refactoring, advance to custom systems
- Self-directed learning — Review the User's Guide to find solutions
- Practical patterns — Learn techniques you'll use in actual projects
Workshop Progression¶
Foundation Workshops¶
Build essential skills through refactoring and practical patterns:
- Refactor to Strong Types — Transform weak types into strongly-typed quantities
- Generic, Type-Safe Interfaces — Make APIs flexible yet safe with
QuantityOf - Extracting Numeric Values — Handle legacy interfaces requiring raw numbers
- Working with Temperatures — Master absolute vs relative temperature handling
- Affine Spaces and Origins — Work with multiple coordinate systems
- Interop with std::chrono — Bridge between time libraries seamlessly
Perfect for...
Integrating mp-units into existing codebases and working with legacy systems.
Extensions Workshops¶
Create domain-specific systems of quantities and units:
- Custom Dimensionless Units — Create strongly-typed counters for business domains (cartons, pallets, trucks)
- Typed Quantities of Same Kind — Distinguish height, width, and turn radius to prevent argument confusion
- Custom Quantity Specifications — Define domain-specific energy types for elevator system design
- Custom Base Dimensions — Create financial dimensions (shares, currency) for portfolio tracking
- Distinct Quantity Kinds — Prevent mixing fluid head and water head in hydraulic engineering
Perfect for...
Building specialized systems for your domain—aviation, robotics, finance, data engineering, etc.
Advanced Workshops¶
Master sophisticated patterns:
- Strongly-Typed Counts — Use dimensionless quantities for graphics coordinates and buffer indices
- Faster-than-Lightspeed Constants — Implement physical constants as compile-time units with automatic cancellation
- Incremental Migration — Gradually adopt mp-units in legacy projects
Perfect for...
Advanced users working on complex systems requiring maximum type safety.
Community and Feedback¶
We'd love to hear from you:
- Questions? Join discussions in our GitHub Discussions
- Found an issue? Report it on GitHub Issues
- Success story? Share it on social media with
#mpunitsor#cplusplus - Suggestions? We're always looking to improve our learning resources
Help Us Improve¶
As you work through tutorials and workshops:
- Let us know if something is unclear
- Suggest additional exercises or topics
- Share patterns you discover
- Report broken Compiler Explorer examples
Try It Today¶
No installation required. Open any tutorial or workshop, and you'll find interactive code editors embedded right in the documentation. Start typing, and the code compiles automatically. You'll be writing type-safe, dimensionally correct code within minutes.
Special thanks to Matt Godbolt and the rest of the Compiler Explorer team for making interactive learning possible.