Would you like to hear about C++ Type traits in std::tr1, and how to use them for compiletime decisions?
Previous Entry
Refactoring your tests...
Next Entry
Type Traits, Part 1
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
Well, yes...
...no...
...maybe...
...only if you talk about runtime implementation...
...I have no idea what you're talking about.
-IV
...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
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
YES
July 10, 2005 04:06 AM
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:
usage:
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.
#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
Advertisement
Latest Entries
C++ Quiz #4
1296 views
C++ Quiz #4
2649 views
C++ Quiz #3
1165 views
C++ Quiz #3
1832 views
C++ Quiz #2
1156 views
Advertisement