From 015dff80a04379fca0633ec7b5c4cbaf48241841 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 14 Sep 2017 13:13:45 +1000 Subject: [PATCH] view: add nulling move operations --- view.hpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/view.hpp b/view.hpp index a027ffe0..57c64fb2 100644 --- a/view.hpp +++ b/view.hpp @@ -39,6 +39,26 @@ namespace util { m_end (last) { ; } + + constexpr + view (const view &rhs) noexcept: + m_begin (rhs.m_begin), + m_end (rhs.m_end) + { ; } + + + // technically we could get away without explicitly defining a move + // constructor here, but by nulling rhs we can more easily use this + // class as a base for unique owning pointers without exposing + // begin/end to them directly. + constexpr view (view &&rhs) noexcept: + view (T{}, T{}) + { + std::swap (m_begin, rhs.m_begin); + std::swap (m_end, rhs.m_end); + } + + template constexpr explicit view (K &klass): @@ -53,6 +73,29 @@ namespace util { m_end (std::end (klass)) { ; } + + view& + operator= (const view &rhs) noexcept + { + m_begin = rhs.m_begin; + m_end = rhs.m_end; + return *this; + } + + + view& + operator= (view &&rhs) noexcept + { + m_begin = rhs.m_begin; + m_end = rhs.m_end; + + m_begin = T{}; + m_end = T{}; + + return *this; + }; + + constexpr T begin (void) noexcept { return m_begin; } constexpr T end (void) noexcept { return m_end; }