GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » Scientific Computing » C++ » The power of templates!
icon14.gif  The power of templates! [message #1560] Fri, 01 April 2005 00:42
Anar Manafov is currently offline  Anar Manafov
Messages: 81
Registered: August 2004
Location: Germany, Darmstadt
continuous participant

From: kp1pc34.gsi.de
There are classes A and B. How to check that B is inherited from class A? Smile Compile-time task.


It could be useful for someone:
template<typename A, typename B>
class isd
{
   class no{};
   class yes{no[2]};
   static yes test(B*);
   static no test(...);
 public:
   enum {is=sizeof(test(static_cast<A*>(0)))==sizeof(yes)};
};

Shocked
Just read the code..........................

Now you understand what this code is made for?! Do you see the power?!

This is just an ART, isn't it? Smile




Extensible Templates: Via Inheritance or Traits?


1 horsepower = 745.699872 Watts
 
Read Message icon14.gif
Previous Topic: Exceptional C++
Next Topic: Anar's Wiki - C++ Development
Goto Forum:
  


Current Time: Wed Oct 09 12:58:40 CEST 2024

Total time taken to generate the page: 0.00846 seconds