index type can only be deduced from class, else it is size_t

This commit is contained in:
Christopher Lackner 2019-08-21 11:24:37 +02:00
parent 22de6f2c56
commit b12ef20fb7

View File

@ -134,21 +134,18 @@ namespace ngcore
private:
template<typename T2>
static constexpr auto check(T2* t) -> typename T2::index_type { return *t; }
// this function is needed for visual because it seems to not lazy evaluate template arguments...
template<typename T2>
static constexpr auto check(T2* t) -> typename std::enable_if_t<std::is_integral_v<T>> {}
static constexpr auto check(...) -> decltype(std::declval<T>().Size())
{ return decltype(std::declval<T>().Size())(); }
static constexpr size_t check(...);
public:
using type = decltype(check((T*) nullptr)); // NOLINT
};
} // namespace detail
// Get index type of object. If object has a typedef index_type this type is returned
// else decltype(obj.Size()) is returned.
// Get index type of object. If object has a typedef index_type it is this type, else size_t
template<typename T>
using index_type = typename detail::IndexTypeHelper<T>::type;
} // namespace ngcore
#endif // NETGEN_CORE_UTILS_HPP