IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue 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
Pranav Sampathkumar
corsika
Commits
220e66c2
Commit
220e66c2
authored
5 years ago
by
Hans Dembinski
Committed by
Maximilian Reininghaus
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Simple enabling and disabling of overloads
parent
2b6deece
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Framework/StackInterface/Stack.h
+4
-10
4 additions, 10 deletions
Framework/StackInterface/Stack.h
Framework/Utilities/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Framework/Utilities/CMakeLists.txt
Framework/Utilities/MetaProgramming.h
+66
-0
66 additions, 0 deletions
Framework/Utilities/MetaProgramming.h
with
71 additions
and
10 deletions
Framework/StackInterface/Stack.h
+
4
−
10
View file @
220e66c2
...
...
@@ -15,6 +15,7 @@
#include
<corsika/stack/StackIteratorInterface.h>
// must be after StackIteratorInterface
#include
<corsika/stack/SecondaryView.h>
#include
<corsika/utl/MetaProgramming.h>
#include
<stdexcept>
#include
<type_traits>
...
...
@@ -72,11 +73,7 @@ namespace corsika::stack {
* if StackDataType is a reference member we *HAVE* to initialize
* it in the constructor, this is typically needed for SecondaryView
*/
template
<
typename
_StackDataType
=
StackDataType
,
typename
=
std
::
enable_if
<
std
::
is_same
<
StackDataType
,
_StackDataType
>
::
value
&&
std
::
is_reference
<
_StackDataType
>::
value
,
void
>>
template
<
typename
_
=
StackDataType
,
typename
=
utl
::
enable_if
<
std
::
is_reference
<
_
>
>>
Stack
(
StackDataType
vD
)
:
fData
(
vD
)
{}
...
...
@@ -89,11 +86,8 @@ namespace corsika::stack {
* stacks, where the inner data container is always a reference
* and cannot be initialized here.
*/
template
<
typename
...
Args
,
typename
_StackDataType
=
StackDataType
,
typename
=
std
::
enable_if
<
std
::
is_same
<
StackDataType
,
_StackDataType
>
::
value
&&
!
std
::
is_reference
<
_StackDataType
>::
value
,
void
>>
template
<
typename
...
Args
,
typename
_
=
StackDataType
,
typename
=
utl
::
disable_if
<
std
::
is_reference
<
_
>
>>
Stack
(
Args
...
args
)
:
fData
(
args
...)
{}
...
...
This diff is collapsed.
Click to expand it.
Framework/Utilities/CMakeLists.txt
+
1
−
0
View file @
220e66c2
...
...
@@ -28,6 +28,7 @@ set (
Bit.h
Singleton.h
CorsikaFenv.h
MetaProgramming.h
)
set
(
...
...
This diff is collapsed.
Click to expand it.
Framework/Utilities/MetaProgramming.h
0 → 100644
+
66
−
0
View file @
220e66c2
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*/
#ifndef _include_corsika_utilties_meta_programming_h_
#define _include_corsika_utilties_meta_programming_h_
#include
<type_traits>
/**
\file MetaProgramming.h
Tools to emulate conditional compilation of method overloads.
```
#include <corsika/utl/MetaProgramming.h>
template <class T>
struct Foo {
template <class U, class = corsika::utl::enable_if<std::reference<U>>>
void enable_only_if_U_is_reference(U x) {}
template <class _ = T, class = corsika::utl::disable_if<std::reference<_>>>
void enable_only_if_T_is_not_reference() {}
};
```
To combine traits, use boost::mp11::mp_and or boost::mp11::mp_or.
```
#include <corsika/utl/MetaProgramming.h>
#include <boost/mp11.hpp>
template <class T>
struct Foo {
template <class U, class = corsika::utl::enable_if<
boost::mp11::mp_and<std::is_reference<T>, std::is_const<T>>
>
void enable_only_if_U_is_const_reference(U x) {}
};
```
Common combined traits may be implemented in this header. For example:
```
template <class T>
using is_cref = boost::mp11::mp_and<std::is_reference<T>, std::is_const<T>>;
```
}
*/
namespace
corsika
::
utl
{
template
<
class
Trait
>
using
enable_if
=
typename
std
::
enable_if
<
(
Trait
::
value
==
true
)
>::
type
;
template
<
class
Trait
>
using
disable_if
=
typename
std
::
enable_if
<
(
Trait
::
value
==
false
)
>::
type
;
}
// namespace corsika::utl
#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