diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-10-30 20:28:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-30 20:28:08 +0000 |
commit | 389898f71ed1d54bd6a81706c058609f054cf6b8 (patch) | |
tree | e42bee2ca2e647bc29af4a11a92e2460bb51ae18 /base/include/hidl | |
parent | 10b76c15f927ad1f30368c2ba89e846377250b48 (diff) | |
parent | 39d9f88b13c6dd5e4d332d332741fb9779ad1714 (diff) | |
download | libhidl-389898f71ed1d54bd6a81706c058609f054cf6b8.tar.gz |
Merge "hidl_enum_range: support const/reverse iteration"
Diffstat (limited to 'base/include/hidl')
-rw-r--r-- | base/include/hidl/HidlSupport.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h index 2d0dc25..43e84c0 100644 --- a/base/include/hidl/HidlSupport.h +++ b/base/include/hidl/HidlSupport.h @@ -997,12 +997,31 @@ std::string toString(const hidl_array<T, SIZE1, SIZE2, SIZES...> &a) { + details::toString(details::const_accessor<T, SIZE1, SIZE2, SIZES...>(a.data())); } +namespace details { +// Never instantiated. Used as a placeholder for template variables. +template <typename T> +struct hidl_invalid_type; + +// HIDL generates specializations of this for enums. See hidl_enum_range. +template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>> +constexpr hidl_invalid_type<T> hidl_enum_values; +} // namespace details + /** - * Every HIDL generated enum generates an implementation of this function. + * Every HIDL generated enum supports this function. * E.x.: for(const auto v : hidl_enum_range<Enum>) { ... } */ template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>> -struct hidl_enum_range; +struct hidl_enum_range { + constexpr auto begin() const { return std::begin(details::hidl_enum_values<T>); } + constexpr auto cbegin() const { return begin(); } + constexpr auto rbegin() const { return std::rbegin(details::hidl_enum_values<T>); } + constexpr auto crbegin() const { return rbegin(); } + constexpr auto end() const { return std::end(details::hidl_enum_values<T>); } + constexpr auto cend() const { return end(); } + constexpr auto rend() const { return std::rend(details::hidl_enum_values<T>); } + constexpr auto crend() const { return rend(); } +}; template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>> struct hidl_enum_iterator { |