view: add make_cview function
This commit is contained in:
parent
6d079554a6
commit
3e9b86f33f
6
view.hpp
6
view.hpp
@ -50,7 +50,7 @@ namespace util {
|
|||||||
constexpr size_t size (void) const noexcept;
|
constexpr size_t size (void) const noexcept;
|
||||||
|
|
||||||
constexpr value_type& operator[] (size_t) 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;
|
bool operator== (view) const noexcept;
|
||||||
|
|
||||||
@ -75,6 +75,10 @@ namespace util {
|
|||||||
auto
|
auto
|
||||||
make_view (T&&) = delete;
|
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<const char*>);
|
||||||
bool operator== (const std::string&, view<char*>);
|
bool operator== (const std::string&, view<char*>);
|
||||||
bool operator== (const std::string&, view<std::string::const_iterator>);
|
bool operator== (const std::string&, view<std::string::const_iterator>);
|
||||||
|
15
view.ipp
15
view.ipp
@ -143,7 +143,7 @@ util::view<T>::size (void) const noexcept
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr
|
constexpr
|
||||||
typename util::view<T>::value_type&
|
const typename util::view<T>::value_type&
|
||||||
util::view<T>::operator[] (size_t idx) const noexcept
|
util::view<T>::operator[] (size_t idx) const noexcept
|
||||||
{
|
{
|
||||||
return m_begin[idx];
|
return m_begin[idx];
|
||||||
@ -184,7 +184,7 @@ template <typename T>
|
|||||||
auto
|
auto
|
||||||
util::make_view (T &t)
|
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
|
auto
|
||||||
util::make_view (const T &t)
|
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) };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user