IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 220e66c2 authored by Hans Dembinski's avatar Hans Dembinski Committed by Maximilian Reininghaus
Browse files

Simple enabling and disabling of overloads

parent 2b6deece
No related branches found
No related tags found
No related merge requests found
......@@ -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...) {}
......
......@@ -28,6 +28,7 @@ set (
Bit.h
Singleton.h
CorsikaFenv.h
MetaProgramming.h
)
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