Anyone that's done a lot of programming using templates knows that the Boost's call traits library is absolutely essential. My question is, do you think that it is essential enough to warrant the use of a macro?

e.g.

#define VALUE(T) boost::call_traits<T>::value_type

And similar for REF, CONST_REF, and PARAM.

Obviously my concern here is the use of macros due to their general evilness, and the use of such potentially common identifiers does no good for namespace pollution.

The next best solution in my opinion is to do the typedefs within your class, but the obvious disadvantage to this method is that it takes an awful lot of typing.

Is there anyone here that has done any large scale C++ development that could shed some light on their practices in this regard?

Thanks in advance.

Kenneth_Gorking
—
2009-08-06T14:07:15Z —
#2

Macros aren't always evil, although they certainly can be. If used properly, they can save you tons of typing, like if you used a single macro to do all the typedefs

Macros aren't always evil, although they certainly can be. If used properly, they can save you tons of typing, like if you used a single macro to do all the typedefs

True, but that only works for class-level typedefs. Global functions would still require the full forms.

JarkkoL
—
2009-08-06T14:29:01Z —
#4

I have done fair amount of template heavy programming, and I don't find call_traits (well, my implementation of it) that useful in practice. I have my:

#define PFC_ARGT(T__) typename type<T__ >::arg

but I don't actually use it anywhere in my 100k lines of engine code, and use the template only in few places.

poita
—
2009-08-06T14:42:40Z —
#5

Hmm, maybe it's just my style of programming, but I find that I need it an awful lot. I must be reading too much Stepanov :/

JarkkoL
—
2009-08-06T14:51:24Z —
#6

Maybe There was a point when I was in my learning phases of template programming and did tend to go a bit overboard with it. Then I realized that other people should be able to read my code as well, so toned it down a bit, but my code is still a bit template heavy by many programmer's standards. I just try to use templates where it's absolutely necessary to give some obvious practical advantage instead of planning for some esoteric corner cases and sacrifying readibility because of that.