RaGa__M
RaGa__M

Reputation: 2571

Multiple aliases for a type T

I want to create multiple aliases for a type, what I really need is like the below,

using MIN = MAX = AVG = nano_t;

(this seems more elegant, less typing, and also there is more than two cases where I have to do this kinda assignment), rather than doing this:

using....
using...
using... every time

but single line assignment doesn't make sense to the compiler as I want it to be. Is there any-other way to do it?

Upvotes: 0

Views: 91

Answers (2)

Quentin
Quentin

Reputation: 63124

using does not permit multiple aliases, but typedef does:

typedef nano_t MIN, MAX, AVG;

Upvotes: 6

The obvious answer is to do it in separate declarations:

using MIN = nano_t;
using MAX = nano_t;
using AVG = nano_t;

If you really want to follow DRY (but I wouldn't bother in such a small example), you can do this:

using min_max_avg_aliased_type = nano_t;
using MIN = min_max_avg_aliased_type;
using MAX = min_max_avg_aliased_type;
using AVG = min_max_avg_aliased_type;

Upvotes: 1

Related Questions