Boost logo

Boost Users :

From: martin f krafft (madduck_at_[hidden])
Date: 2005-05-14 09:25:58


Dear all,

another MPL question (at least I think it's the domain of MPL):

I have a templated class Foo and need to make an instance based on
the type of an instance at various points in the code, which is
simple:
  
  template <typename T>
    Foo<T> get_foo_for(T const&) { return Foo<T>; }
  
  //...
  get_foo_for(myObj).doSomethingWithFoo();

At times, I don't have an instance of an object, just the typename.
I do not want to assume that all types are default constructible
(which could be expensive anyway), so I have to do:

  Foo<T>().doSomethingWithFoo();

I am hiding these two behind two separate macros which I would like
to unify. The situation is actually more complex but boils down to
the following question:

How can I create a macro (#define) such that its definition does
different things when passed an instance or a typename.
Something like:

  if is_type(Arg) do_this();
  else do_that();

Again, I cannot figure this out from the MPL docs. There is
enable_if and if_c, but both seem to deal with the definition of
symbols and/or types, not with the selection of functions to call.

I appreciate any hint.

-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net_at_madduck
 
invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver!
spamtraps: madduck.bogus_at_[hidden]
 
"arguments are extremely vulgar,
 for everyone in good society
 holds exactly the same opinion."
                                                        -- oscar wilde



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net