Skip to content
Snippets Groups Projects
Commit 8830c1c2 authored by Christian Engwer's avatar Christian Engwer
Browse files

add IsBaseOf<...> to test inheritance

[[Imported from SVN: r5741]]
parent 3caa3be0
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ namespace Dune
/**
* @file
* @brief Traits for type conversions and type information.
* @author Markus Blatt
* @author Markus Blatt, Christian Engwer
*/
/** @addtogroup Common
*
......@@ -171,7 +171,10 @@ namespace Dune
#endif
/**
* @brief Checks wether a type is derived from another.
* @brief Checks wether a type is convertible to another.
*
* @tparam From type you want to convert
* @tparam To type you want to obtain
*
* Inspired by
* <A HREF="http://www.kotiposti.net/epulkkin/instructive/base-class-determination.html"> this website</A>
......@@ -235,6 +238,30 @@ namespace Dune
enum { exists=true, isTwoWay=true, sameType=true};
};
/**
* @brief Checks wether a type is derived from another.
*
* @tparam Base the potential base class you want to test for
* @tparam Derived type you want to test
*
* Similar idea to
* <A HREF="http://www.kotiposti.net/epulkkin/instructive/base-class-determination.html"> this website</A>
*/
template <class Base, class Derived>
class IsBaseOf
{
typedef char Small;
struct Big {char dummy[2];};
static Small test(Base*);
static Big test(...);
static typename TypeTraits< Derived* >::ReferredType &makePtr ();
public:
enum {
/** @brief True if Base is a base class of Derived. */
value = sizeof(test(makePtr())) == sizeof(Small)
};
};
/**
* @brief Checks wether two types are interoperable.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment