Skip to content

Instantly share code, notes, and snippets.

@tamaroth
Created September 10, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamaroth/f5fe9a8c74170fb48a512f86f015c16f to your computer and use it in GitHub Desktop.
Save tamaroth/f5fe9a8c74170fb48a512f86f015c16f to your computer and use it in GitHub Desktop.
Is type iterable trait.
namespace detail {
template<typename T>
auto is_iterable_impl(int) -> decltype(
std::begin(std::declval<T&>()) != std::end(std::declval<T&>()),
++std::declval<decltype(std::begin(std::declval<T&>()))&>(),
void(*std::begin(std::declval<T&>())),
std::true_type{}
);
template <typename T>
std::false_type is_iterable_impl(...);
}
///
/// Is the given type iterable?
///
template<typename T>
using is_iterable = decltype(detail::is_iterable_impl<T>(0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment