Skip to content

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 distance to 200 * m and watch the speed update
  • Try adding an invalid operation like distance + time and see the compiler error instantly
  • Experiment with different units: distance = 100 * km still 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

  1. Start with Tutorials — Complete all 14 lessons (~3.5 hours)
  2. Try the Foundation Workshops — Practice refactoring patterns
  3. Explore Examples — Study complete applications
  4. Dive into specific topics in the User's Guide as needed

For Experienced Developers

Already familiar with units libraries?

  1. Skim Quick Start tutorials (30 min)
  2. Focus on Type Safety tutorials (~1 hour)
  3. Jump to Customization and Advanced Workshops
  4. Reference the Systems documentation for your domain

For Migration

Coming from another library?

  1. Read the relevant Migration Guide
  2. Complete the Workshop: Incremental Migration
  3. 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:

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:

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:

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:

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:

Perfect for...

Integrating mp-units into existing codebases and working with legacy systems.

Extensions Workshops

Create domain-specific systems of quantities and units:

Perfect for...

Building specialized systems for your domain—aviation, robotics, finance, data engineering, etc.

Advanced Workshops

Master sophisticated patterns:

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 #mpunits or #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.

Start Learning →


Special thanks to Matt Godbolt and the rest of the Compiler Explorer team for making interactive learning possible.

Comments