Jump to content


[C++] Call-traits macro


6 replies to this topic

#1 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 06 August 2009 - 01:09 PM

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.

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 06 August 2009 - 02:07 PM

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 :)
"Stupid bug! You go squish now!!" - Homer Simpson

#3 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 06 August 2009 - 02:28 PM

Kenneth Gorking said:

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.

#4 JarkkoL

    Senior Member

  • Members
  • PipPipPipPip
  • 475 posts

Posted 06 August 2009 - 02:29 PM

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.

#5 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 06 August 2009 - 02:42 PM

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

#6 JarkkoL

    Senior Member

  • Members
  • PipPipPipPip
  • 475 posts

Posted 06 August 2009 - 02:51 PM

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.

#7 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 07 August 2009 - 12:52 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users