Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Koch
dune-common
Commits
8830c1c2
Commit
8830c1c2
authored
15 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
add IsBaseOf<...> to test inheritance
[[Imported from SVN: r5741]]
parent
3caa3be0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/typetraits.hh
+29
-2
29 additions, 2 deletions
dune/common/typetraits.hh
with
29 additions
and
2 deletions
dune/common/typetraits.hh
+
29
−
2
View file @
8830c1c2
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment