Specialize template functions

Specialize template functions in C++ — with the four heights of help laid out: do it now, make it easier for the next person to accept, work out the right move when you are stuck, and learn the pattern so it stops coming back.

4prompt heights
Open it in the interactive atlas →

The four heights

The same task, four distances: today's deadline, the next reviewer, the stuck moment, the pattern.

Execute — do the immediate task

+
I have a templated utility that takes two numeric types and returns their average. Compile-time…
I have a templated utility that takes two numeric types and returns their average. Compile-time errors occur when one argument is an integer type and the other a floating type. Specialize the template so calls like average(3, 4.0) and average(3u, 4u) compile and produce the mathematically correct type and value; prefer the wider type and preserve signedness rules. Check common edge cases: overflow for integers, NaN for floats.

Improve — make it easier to accept

+
Before I commit this set of template overloads for our math library, make approval easy for…
Before I commit this set of template overloads for our math library, make approval easy for reviewers in the repo: surface a one-line summary of the overload resolution rules up top, show example calls and outcomes for mixed int/float and signed/unsigned pairs, and flag any surprising conversions or potential undefined behavior like integer overflow. Suggest the minimal compile-time tests reviewers will expect.

Decide — diagnose the stuck moment

+
I just got a build break from average(3, 4.0) in the core math file. The CI error says no matching…

A template call failed only for mixed int/float arguments.

I just got a build break from average(3, 4.0) in the core math file. The CI error says no matching function for call. I know template specialization exists but I’m not certain which combination of overloads and enable-ifs will keep overload resolution clear and not bloat instantiations. Recommend the likely cause and the best next implementation: either add a forwarding overload that promotes to common_type, or SFINAE-constrain the original template. Explain trade-offs and a one-change patch to try first.

Become — change the pattern

+
Across several modules we keep adding single-purpose template specializations to silence compile…

We keep piling ad-hoc template overloads to fix single-call build failures.

Across several modules we keep adding single-purpose template specializations to silence compile errors from mixed types. That creates brittle overload resolution and slow compile times. Where are we losing time and credibility, and what habit should we change? Recommend a consistent rule for numeric templates — for example: always accept parameters by value, immediately std::common_type_t them, and write a small set of well-documented wrappers — plus a checklist for new template additions to prevent future sprawl.

Next to this one

Other programming language work people do in C++.

Every task here came from the work, not from a feature list — which is why the prompts name what you want done and never the button that does it. The tool changes; the work does not.
Copyright © LLOS.ai · 2026 — original pedagogy, voice, and design — all rights reserved.

The rest of the map

Same library, five ways in.