From a4acfca1012f8362dfbf6ade3608390ce41811f7 Mon Sep 17 00:00:00 2001
From: Olivier BICHLER <olivier.bichler@cea.fr>
Date: Mon, 2 Oct 2023 11:55:47 +0200
Subject: [PATCH] Fixed bug #8

---
 include/aidge/utils/StaticAttributes.hpp | 27 ++++++++++++------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/include/aidge/utils/StaticAttributes.hpp b/include/aidge/utils/StaticAttributes.hpp
index 4687ddbb2..98011b748 100644
--- a/include/aidge/utils/StaticAttributes.hpp
+++ b/include/aidge/utils/StaticAttributes.hpp
@@ -95,11 +95,11 @@ public:
         assert(false && "attribute not found");
     }
 
-    template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1>
+    template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
     constexpr typename std::enable_if<(SIZE > 0), R&>::type getAttr(std::size_t i) {
-        if (i == SIZE) {
-            if (std::is_same<R, typename std::tuple_element<SIZE,std::tuple<T...>>::type>::value) {
-                return reinterpret_cast<R&>(std::get<SIZE>(mAttrs));
+        if (i == SIZE-1) {
+            if (std::is_same<R, typename std::tuple_element<SIZE-1,std::tuple<T...>>::type>::value) {
+                return reinterpret_cast<R&>(std::get<SIZE-1>(mAttrs));
             }
             else {
                 assert(false && "wrong attribute type");
@@ -110,25 +110,24 @@ public:
         }
     }
 
-    template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1>
-    [[noreturn]] constexpr typename std::enable_if<(SIZE <= 0), R&>::type getAttr(std::size_t /*i*/) {
+    template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
+    [[noreturn]] constexpr typename std::enable_if<(SIZE == 0), R&>::type getAttr(std::size_t /*i*/) {
         assert(false && "attribute not found");
     }
 
-    template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1>
-    constexpr typename std::enable_if<(SIZE > 0), std::string>::type getAttrType(std::size_t i) const {
-        if (i == SIZE) {
-            return typeid(typename std::tuple_element<SIZE,std::tuple<T...>>::type).name();
+    template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
+    constexpr typename std::enable_if<(SIZE > 0), const std::type_info&>::type getAttrType(std::size_t i) const {
+        if (i == SIZE-1) {
+            return typeid(typename std::tuple_element<SIZE-1,std::tuple<T...>>::type);
         }
         else {
             return getAttrType<SIZE-1>(i);
         }
     }
 
-    template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1>
-    constexpr typename std::enable_if<(SIZE <= 0), std::string>::type getAttrType(std::size_t /*i*/) const {
+    template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
+    [[noreturn]] constexpr typename std::enable_if<(SIZE == 0), const std::type_info&>::type getAttrType(std::size_t /*i*/) const {
         assert(false && "attribute not found");
-        return std::string();  // useless, but makes MSVC happy
     }
 
     constexpr const std::tuple<T...>& getStaticAttributes() const {
@@ -153,7 +152,7 @@ public:
     constexpr std::string getAttrType(const std::string& name) const override final {
         for (std::size_t i = 0; i < size(EnumStrings<ATTRS_ENUM>::data); ++i) {
             if (name == EnumStrings<ATTRS_ENUM>::data[i]) {
-                return getAttrType(i);
+                return getAttrType(i).name();
             }
         }
 
-- 
GitLab