base: define is_iterable type trait

Change-Id: I38bb0ddcbb95645797f1d20724b78aff3bef4580
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71838
Maintainer: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
Gabriel Busnot
2023-06-20 19:09:53 +00:00
committed by Gabriel B.
parent 91b4540477
commit 2f327fa2b8

View File

@@ -27,8 +27,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BASE_TYPETRAITS_HH__
#define __BASE_TYPETRAITS_HH__
#ifndef BASE_TYPETRAITS_HH
#define BASE_TYPETRAITS_HH
#include <tuple>
#include <type_traits>
@@ -92,6 +92,19 @@ template<auto F>
using MemberFunctionArgsTuple_t =
typename MemberFunctionSignature<decltype(F)>::argsTuple_t;
// iterable type trait
template <typename, typename = void>
struct is_iterable: std::false_type {};
template <typename T>
struct is_iterable<T,
std::void_t<decltype(begin(std::declval<T>())),
decltype(end(std::declval<T>()))>>: std::true_type {};
template <typename T>
constexpr bool is_iterable_v = is_iterable<T>::value;
} // namespace gem5
#endif // __BASE_TYPETRAITS_HH__
#endif // BASE_TYPETRAITS_HH