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
47c5289d
Commit
47c5289d
authored
17 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
started a better implementation the static assertions
[[Imported from SVN: r5039]]
parent
0dcb3578
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/static_assert.hh
+67
-0
67 additions, 0 deletions
common/static_assert.hh
with
67 additions
and
0 deletions
common/static_assert.hh
0 → 100644
+
67
−
0
View file @
47c5289d
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_STATIC_ASSERT_HH
#define DUNE_STATIC_ASSERT_HH
/**
\brief Helper template so that compilation fails if condition is not true.
If the condition is true a static function yes is available, othewise the
only function available is no().
Example for compile time check whether two types are the same:
\code
IsTrue<is_same<int,int>::value>::yes(); //
IsTrue<is_same<bool,int>::value>::yes(); // false, will trigger a compile time error
\endcode
A test that trigger a compile time error if condition is true:
\code
IsTrue<condition>::no()
\endcode
*/
template
<
bool
condition
>
struct
IsTrue
{
static
void
no
()
{};
};
template
<
>
struct
IsTrue
<
true
>
{
static
void
yes
()
{};
};
#include
<iostream>
// Taken from BOOST
//
// Helper macro CPPMAGIC_JOIN:
// The following piece of macro magic joins the two
// arguments together, even when one of the arguments is
// itself a macro (see 16.3.1 in C++ standard). The key
// is that macro expansion of macro arguments does not
// occur in CPPMAGIC_DO_JOIN2 but does in CPPMAGIC_DO_JOIN.
//
#define CPPMAGIC_JOIN( X, Y ) CPPMAGIC_DO_JOIN( X, Y )
#define CPPMAGIC_DO_JOIN( X, Y ) CPPMAGIC_DO_JOIN2(X,Y)
#define CPPMAGIC_DO_JOIN2( X, Y ) X ## Y
template
<
bool
x
>
struct
static_assert_failure
;
template
<
>
struct
static_assert_failure
<
true
>
{
};
template
<
int
x
>
struct
static_assert_test
{};
/**
dune_static_assert(1<=2, "fehler");
dune_static_assert(1<=3, "fehler");
dune_static_assert(3<=2, "fehler");
*/
#define dune_static_assert(B,MSG) \
typedef static_assert_test<\
sizeof(static_assert_failure< (bool)( B )>)\
> CPPMAGIC_JOIN (dune_static_assert_typedef_, __LINE__)
#endif
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