0
101 Aug 06, 2009 at 13:09

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?

6 Replies

0
101 Aug 06, 2009 at 14:07

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 :)

0
101 Aug 06, 2009 at 14:28

@Kenneth Gorking

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.

0
102 Aug 06, 2009 at 14:29

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.

0
101 Aug 06, 2009 at 14:42

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 :/

0
102 Aug 06, 2009 at 14:51

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.

0
101 Aug 07, 2009 at 12:52

Isn’t it a pain when other people need to understand your code? :)