view: add make_cview function

This commit is contained in:
Danny Robson 2016-12-06 15:18:49 +11:00
parent 6d079554a6
commit 3e9b86f33f
2 changed files with 17 additions and 4 deletions

View File

@ -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 <typename T>
auto
make_cview (const T&);
bool operator== (const std::string&, view<const char*>);
bool operator== (const std::string&, view<char*>);
bool operator== (const std::string&, view<std::string::const_iterator>);

View File

@ -143,7 +143,7 @@ util::view<T>::size (void) const noexcept
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr
typename util::view<T>::value_type&
const typename util::view<T>::value_type&
util::view<T>::operator[] (size_t idx) const noexcept
{
return m_begin[idx];
@ -184,7 +184,7 @@ template <typename T>
auto
util::make_view (T &t)
{
return util::view<decltype(std::begin (t))> { t.begin (), t.end () };
return util::view<decltype(std::begin (t))> { std::begin (t), std::end (t) };
}
@ -193,5 +193,14 @@ template <typename T>
auto
util::make_view (const T &t)
{
return util::view<decltype(std::cbegin (t))> { t.cbegin (), t.cend () };
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}
//-----------------------------------------------------------------------------
template <typename T>
auto
util::make_cview (const T &t)
{
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}