view: allow construction from anything that has begin/end

This commit is contained in:
Danny Robson 2018-12-19 17:12:28 +11:00
parent 499fa4d190
commit fb7c989487

View File

@ -44,18 +44,28 @@ namespace cruft {
m_end (last)
{ ; }
template <
typename ContainerT,
typename = std::enable_if_t<is_container_v<std::decay_t<ContainerT>>,void>
typename = std::void_t<
decltype (std::declval<ContainerT&> ().begin ()),
decltype (std::declval<ContainerT&> ().end ())
>
view (ContainerT &rhs):
view (rhs.begin (), rhs.end ())
>
view (ContainerT &rhs) noexcept (
noexcept (std::declval<ContainerT> ().begin ()) &&
noexcept (std::declval<ContainerT> ().end ())
)
: view (rhs.begin (), rhs.end ())
{ ; }
template <
typename ContainerT,
typename = std::enable_if_t<is_container_v<std::decay_t<ContainerT>>,void>
typename = std::void_t<
decltype (std::declval<ContainerT const&> ().begin ()),
decltype (std::declval<ContainerT const&> ().end ())
>
>
view (const ContainerT &rhs):
view (rhs.begin (), rhs.end ())
@ -447,12 +457,14 @@ namespace cruft {
template <typename ContainerT>
view (ContainerT&) -> view<
typename ContainerT::iterator
decltype (std::declval<ContainerT&> ().begin ()),
decltype (std::declval<ContainerT&> ().end ())
>;
template <typename ContainerT>
view (const ContainerT&) -> view<
typename ContainerT::const_iterator
decltype (std::declval<ContainerT const&> ().begin ()),
decltype (std::declval<ContainerT const&> ().end ())
>;
// base + count constructor