diff --git a/adapter.hpp b/adapter.hpp index 7bffa874..a585e222 100644 --- a/adapter.hpp +++ b/adapter.hpp @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2015-2018 Danny Robson + * Copyright 2015-2019 Danny Robson */ #include @@ -13,6 +13,31 @@ namespace cruft::adapter { namespace container { + /// An identity proxy for a referenced container. + /// + /// Provided for symmetry with `reverse` and others, so as to allow a + /// common template interface. + template + class identity { + public: + identity (ContainerT &_target) + : m_target (_target) + { ; } + + decltype(auto) begin (void) & { return m_target.begin (); } + decltype(auto) end (void) & { return m_target.end (); } + + decltype(auto) begin (void) const& { return m_target.begin (); } + decltype(auto) end (void) const& { return m_target.end (); } + + decltype(auto) cbegin (void) const& { return m_target.cbegin (); } + decltype(auto) cend (void) const& { return m_target.cend (); } + + private: + ContainerT &m_target; + }; + + /// Creates a reversed proxy for a referenced container. /// /// The target container must remain an l-value.