IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 122999d3 authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch 'simpler_concept_checks' into 'master'

Simple enabling and disabling of overloads

See merge request AirShowerPhysics/corsika!104
parents dd38818a ba971aa1
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <corsika/stack/StackIteratorInterface.h> #include <corsika/stack/StackIteratorInterface.h>
// must be after StackIteratorInterface // must be after StackIteratorInterface
#include <corsika/stack/SecondaryView.h> #include <corsika/stack/SecondaryView.h>
#include <corsika/utl/MetaProgramming.h>
#include <stdexcept> #include <stdexcept>
#include <type_traits> #include <type_traits>
...@@ -72,11 +73,7 @@ namespace corsika::stack { ...@@ -72,11 +73,7 @@ namespace corsika::stack {
* if StackDataType is a reference member we *HAVE* to initialize * if StackDataType is a reference member we *HAVE* to initialize
* it in the constructor, this is typically needed for SecondaryView * it in the constructor, this is typically needed for SecondaryView
*/ */
template < template <typename _ = StackDataType, typename = utl::enable_if<std::is_reference<_>>>
typename _StackDataType = StackDataType,
typename = std::enable_if<std::is_same<StackDataType, _StackDataType>::value &&
std::is_reference<_StackDataType>::value,
void>>
Stack(StackDataType vD) Stack(StackDataType vD)
: fData(vD) {} : fData(vD) {}
...@@ -89,11 +86,8 @@ namespace corsika::stack { ...@@ -89,11 +86,8 @@ namespace corsika::stack {
* stacks, where the inner data container is always a reference * stacks, where the inner data container is always a reference
* and cannot be initialized here. * and cannot be initialized here.
*/ */
template < template <typename... Args, typename _ = StackDataType,
typename... Args, typename _StackDataType = StackDataType, typename = utl::disable_if<std::is_reference<_>>>
typename = std::enable_if<std::is_same<StackDataType, _StackDataType>::value &&
!std::is_reference<_StackDataType>::value,
void>>
Stack(Args... args) Stack(Args... args)
: fData(args...) {} : fData(args...) {}
......
...@@ -28,6 +28,7 @@ set ( ...@@ -28,6 +28,7 @@ set (
Bit.h Bit.h
Singleton.h Singleton.h
CorsikaFenv.h CorsikaFenv.h
MetaProgramming.h
) )
set ( set (
......
/*
* (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
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