• entries
    146
  • comments
    436
  • views
    197363


8 Comments


Recommended Comments

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

Share this comment


Link to comment
Well, yes...

...no...

...maybe...

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

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

-IV

Share this comment


Link to comment
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

Share this comment


Link to comment
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.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now