Skip to content
Snippets Groups Projects
Commit 0900df9f authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[TypeTraits] Add new type trait is_indexable

is_indexable can be used to test whether a type can be indexed (via
operator[]).
parent 30c896f8
No related branches found
No related tags found
No related merge requests found
......@@ -404,6 +404,23 @@ namespace Dune
static const bool value = true;
};
namespace {
template<typename T, typename I, decltype(std::declval<T>()[std::declval<I>()],0) = 0>
auto _is_indexable(T*) -> std::true_type;
template<typename T, typename I>
auto _is_indexable(void*) -> std::false_type;
}
//! Type trait to determine whether an instance of T has an operator[](I), i.e. whether
//! it can be indexed with an index of type I.
template<typename T, typename I = std::size_t>
struct is_indexable
: public decltype(_is_indexable<T,I>(std::declval<T*>()))
{};
/** @} */
}
#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