From 8f9236bc366f1ab59168c34e72a1ee8c9d07c581 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Tue, 12 Feb 2019 16:15:40 +0100
Subject: [PATCH] fixed Stack enable_if

---
 Framework/StackInterface/ParticleBase.h        |  3 ++-
 Framework/StackInterface/Stack.h               | 17 +++++++++++++----
 Framework/StackInterface/testStackInterface.cc |  4 +---
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/Framework/StackInterface/ParticleBase.h b/Framework/StackInterface/ParticleBase.h
index ef85de7af..d145c1e88 100644
--- a/Framework/StackInterface/ParticleBase.h
+++ b/Framework/StackInterface/ParticleBase.h
@@ -117,13 +117,14 @@ namespace corsika::stack {
     using T::GetStackData;
 
   public:
+    /*
     template <typename... Args1, typename... Args2>
     void SetParticleData(Args1... args1, Args2... args2) {
       T::SetParticleData(args1...);
     }
-
     template <typename... Args1, typename... Args2>
     void SetParticleData(T& p, Args1... args1, Args2... args2) {}
+    */
   };
 
 } // namespace corsika::stack
diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h
index e917f0a72..4626ddb9a 100644
--- a/Framework/StackInterface/Stack.h
+++ b/Framework/StackInterface/Stack.h
@@ -67,11 +67,17 @@ namespace corsika::stack {
         delete; ///< since Stack can be very big, we don't want to copy it
 
   public:
+    //Stack() { Init(); }
+
     /**
-     * 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
      */
-    template <typename = std::enable_if_t<std::is_reference<StackDataType>{}>>
+    template <
+        typename _StackDataType = StackDataType,
+        typename = std::enable_if<std::is_same<StackDataType, _StackDataType>::value &&
+                                    std::is_reference<_StackDataType>::value,
+                                void>>
     Stack(StackDataType vD)
         : fData(vD) {}
 
@@ -80,8 +86,11 @@ namespace corsika::stack {
      * StackDataType user class. If the user did not provide a suited
      * constructor this will fail with an error message.
      */
-    template <typename... Args,
-              typename = std::enable_if_t<!std::is_reference<StackDataType>{}>>
+    template <
+        typename... Args, typename _StackDataType = StackDataType,
+        typename = std::enable_if<std::is_same<StackDataType, _StackDataType>::value &&
+                                    !std::is_reference<_StackDataType>::value,
+                                void >>
     Stack(Args... args)
         : fData(args...) {}
 
diff --git a/Framework/StackInterface/testStackInterface.cc b/Framework/StackInterface/testStackInterface.cc
index 5d4de9dae..8acfa5aba 100644
--- a/Framework/StackInterface/testStackInterface.cc
+++ b/Framework/StackInterface/testStackInterface.cc
@@ -33,7 +33,6 @@ using namespace corsika::stack;
 using namespace std;
 
 typedef Stack<TestStackData, TestParticleInterface> StackTest;
-typedef StackTest::ParticleInterfaceType Particle;
 
 TEST_CASE("Stack", "[Stack]") {
 
@@ -48,7 +47,6 @@ TEST_CASE("Stack", "[Stack]") {
 
     // construct a valid Stack object
     StackTest s;
-    s.Init();
     s.Clear();
     s.AddParticle(std::tuple{0.});
     s.Copy(s.cbegin(), s.begin());
@@ -98,7 +96,7 @@ TEST_CASE("Stack", "[Stack]") {
     StackTest s;
     REQUIRE(s.GetSize() == 0);
     auto iter = s.AddParticle(std::tuple{9.9});
-    Particle& p = *iter; // also this is valid to access particle data
+    StackTest::ParticleInterfaceType& p = *iter; // also this is valid to access particle data
     REQUIRE(s.GetSize() == 1);
     p.AddSecondary(std::tuple{4.4});
     REQUIRE(s.GetSize() == 2);
-- 
GitLab