From 3e9b86f33f01f064ddf0dedaa98a30ba72d3f1ad Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 6 Dec 2016 15:18:49 +1100 Subject: [PATCH] view: add make_cview function --- view.hpp | 6 +++++- view.ipp | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/view.hpp b/view.hpp index 2c3775c0..ca6fb705 100644 --- a/view.hpp +++ b/view.hpp @@ -50,7 +50,7 @@ namespace util { constexpr size_t size (void) const noexcept; constexpr value_type& operator[] (size_t) noexcept; - constexpr value_type& operator[] (size_t) const noexcept; + constexpr const value_type& operator[] (size_t) const noexcept; bool operator== (view) const noexcept; @@ -75,6 +75,10 @@ namespace util { auto make_view (T&&) = delete; + template + auto + make_cview (const T&); + bool operator== (const std::string&, view); bool operator== (const std::string&, view); bool operator== (const std::string&, view); diff --git a/view.ipp b/view.ipp index 0b526c5d..87ba01d5 100644 --- a/view.ipp +++ b/view.ipp @@ -143,7 +143,7 @@ util::view::size (void) const noexcept /////////////////////////////////////////////////////////////////////////////// template constexpr -typename util::view::value_type& +const typename util::view::value_type& util::view::operator[] (size_t idx) const noexcept { return m_begin[idx]; @@ -184,7 +184,7 @@ template auto util::make_view (T &t) { - return util::view { t.begin (), t.end () }; + return util::view { std::begin (t), std::end (t) }; } @@ -193,5 +193,14 @@ template auto util::make_view (const T &t) { - return util::view { t.cbegin (), t.cend () }; + return util::view { std::cbegin (t), std::cend (t) }; +} + + +//----------------------------------------------------------------------------- +template +auto +util::make_cview (const T &t) +{ + return util::view { std::cbegin (t), std::cend (t) }; }