Skip to content
Snippets Groups Projects
Commit a4acfca1 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Fixed bug #8

parent ab7187c2
No related branches found
No related tags found
1 merge request!16Unified interface for attributes
Pipeline #32290 failed
...@@ -95,11 +95,11 @@ public: ...@@ -95,11 +95,11 @@ public:
assert(false && "attribute not found"); 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) { constexpr typename std::enable_if<(SIZE > 0), R&>::type getAttr(std::size_t i) {
if (i == SIZE) { if (i == SIZE-1) {
if (std::is_same<R, typename std::tuple_element<SIZE,std::tuple<T...>>::type>::value) { if (std::is_same<R, typename std::tuple_element<SIZE-1,std::tuple<T...>>::type>::value) {
return reinterpret_cast<R&>(std::get<SIZE>(mAttrs)); return reinterpret_cast<R&>(std::get<SIZE-1>(mAttrs));
} }
else { else {
assert(false && "wrong attribute type"); assert(false && "wrong attribute type");
...@@ -110,25 +110,24 @@ public: ...@@ -110,25 +110,24 @@ public:
} }
} }
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>
[[noreturn]] constexpr typename std::enable_if<(SIZE <= 0), R&>::type getAttr(std::size_t /*i*/) { [[noreturn]] constexpr typename std::enable_if<(SIZE == 0), R&>::type getAttr(std::size_t /*i*/) {
assert(false && "attribute not found"); assert(false && "attribute not found");
} }
template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1> template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
constexpr typename std::enable_if<(SIZE > 0), std::string>::type getAttrType(std::size_t i) const { constexpr typename std::enable_if<(SIZE > 0), const std::type_info&>::type getAttrType(std::size_t i) const {
if (i == SIZE) { if (i == SIZE-1) {
return typeid(typename std::tuple_element<SIZE,std::tuple<T...>>::type).name(); return typeid(typename std::tuple_element<SIZE-1,std::tuple<T...>>::type);
} }
else { else {
return getAttrType<SIZE-1>(i); return getAttrType<SIZE-1>(i);
} }
} }
template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value-1> template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
constexpr typename std::enable_if<(SIZE <= 0), std::string>::type getAttrType(std::size_t /*i*/) const { [[noreturn]] constexpr typename std::enable_if<(SIZE == 0), const std::type_info&>::type getAttrType(std::size_t /*i*/) const {
assert(false && "attribute not found"); assert(false && "attribute not found");
return std::string(); // useless, but makes MSVC happy
} }
constexpr const std::tuple<T...>& getStaticAttributes() const { constexpr const std::tuple<T...>& getStaticAttributes() const {
...@@ -153,7 +152,7 @@ public: ...@@ -153,7 +152,7 @@ public:
constexpr std::string getAttrType(const std::string& name) const override final { constexpr std::string getAttrType(const std::string& name) const override final {
for (std::size_t i = 0; i < size(EnumStrings<ATTRS_ENUM>::data); ++i) { for (std::size_t i = 0; i < size(EnumStrings<ATTRS_ENUM>::data); ++i) {
if (name == EnumStrings<ATTRS_ENUM>::data[i]) { if (name == EnumStrings<ATTRS_ENUM>::data[i]) {
return getAttrType(i); return getAttrType(i).name();
} }
} }
......
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