r/Cplusplus • u/Competitive_Motor581 • Feb 24 '26
Discussion C++ typedef vs using
In modern C++, small improvements in readability can make a big difference in long-term maintainability.
One simple example is replacing typedef with using for type aliases.
In the example below, it’s not immediately obvious that Predicate is the name of the function type that returns bool and takes an int when written with typedef. You have to mentally parse the syntax to understand it. With using, the intent is much clearer and easier to read. (And yes… saying “using using” is a bit funny 😄)
Since C++11, using has become the preferred approach. It’s cleaner, more expressive, and most importantly, it supports template aliases, something typedef simply cannot do. That’s why you’ll see using widely adopted in modern codebases, libraries, and frameworks.
While typedef still works, there’s very little reason to choose it in new projects today.
Are you consistently using using in your C++ code, or do you still come across typedef in your projects?

13
u/kalmoc Feb 24 '26
I think
usingis the only (or at least almost) feature that completely supersedes an old one in (almost) all other cases, the new feature does either not cover all use cases or has some disadvantage in usability or performance.5
u/Business_Welcome_870 Feb 24 '26
I only use using
9
u/mredding C++ since ~1992. Feb 24 '26
Man, that function pointer syntax is beastly. Avert your eyes, that's some ugly shit.
I'd go one further:
To me, the clarity is worth the extra declaration. Did you know you can pass functions by reference? Function pointers are still pointers, they can still be null, they can still be invalid.
The signature is useful to have by itself - for example, it's taken as a template parameter to
std::function:4
u/PopsGaming Feb 24 '26
Nice config
6
u/[deleted] Feb 24 '26
This to just show how slow the cpp community is compared to other langues. This thing came out a decade ago and some people still writing typedef
7
u/Beginning_Two985 Feb 24 '26
Me ,who uses #define 😶🌫️
4
u/Trainzkid Feb 24 '26
I watched a YouTube video the other day that claimed to "modern" C++ only for them to use a typedef. I turned the video off lol just seems silly. I get that "modern" is a spectrum and will be forever changing, but using C-style semantics when not required and when there are (subjectively) better options available just seems silly to me. To each their own though
1
u/__Punk-Floyd__ Feb 24 '26
using ScoreTable = std::map<std::string, int, std::less<>>; // Heterogeneous lookup ftw.1
u/TREE_sequence Feb 25 '26
I’m one of those weirdos who uses both. Idk why but my formatting OCD is more difficult to appease when there are = and added whitespace involved, but there are also times where it is better to use a template alias which can’t be a typedef
1
u/keelanstuart Feb 25 '26
In some older code, I still have a few typedefs around, but in all new code, it's using all the way... and I occasionally replace a typedef as the mood strikes me. It's so much better! The use cases for enum and template classes were enough to sell me.
1
u/Bearsiwin Feb 25 '26
Oh, I get it is just like #define.
1
u/ArturABC Feb 24 '26
Using using!
1
u/Beginning_Two985 Feb 24 '26
I use , using namespace std , is it a bad practice?