So...

Published July 09, 2005
Advertisement
Would you like to hear about C++ Type traits in std::tr1, and how to use them for compiletime decisions?
0 likes 8 comments

Comments

Seriema
a friend rolled his own for his event system. there seems to be alot of uses for traits, especially when passing parameters around (the classic "pass a copy for PODs and const refs for the rest"). I'd sure like to hear more, especially the one proposed to C++ :D
July 09, 2005 04:04 PM
TraderJack
Well, yes...

...no...

...maybe...

...only if you talk about runtime implementation...

...I have no idea what you're talking about.

-IV
July 09, 2005 05:44 PM
Wavinator
Ooooo, compile time decision making sounds SEXY! [grin]
July 09, 2005 07:55 PM
_the_phantom_
i vote yes! [grin]
July 09, 2005 09:09 PM
Muhammad Haggag
Washu, you know we're going to read and enjoy anything you write. Plus, it'd be great to read some of your insights on C++ for a change (as opposed to the usual .NET tidbits). In short:

YES
July 10, 2005 04:06 AM
snk_kid
I use type traits quite abit in my code but less on its own more with boost MPL. I have some simple code that does what Seriema was describing about passing parameters by value or constant reference:


#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_fundamental.hpp>

template < typename Tq >
struct param_type : public boost::mpl::eval_if<
	boost::is_fundamental<Tq>, 
	boost::mpl::identity<Tq>,
	boost::add_reference<Tq const>
> {};


usage:


template < typename Tp >
struct foo {   void bar(typename param_type<Tp>::type) {}   };


its nifty [grin].

There is all kind of things you can do even make domain specific embedded languages, if you get the book C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond you'll see all the ways in which you can use them.
July 10, 2005 04:41 AM
evolutional
Yes.
July 10, 2005 07:25 AM
Ravuya
Anything other than .NET would be appreciated.
July 10, 2005 10:36 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement