adapter: add the 'identity' adapter

This commit is contained in:
Danny Robson 2019-08-06 14:31:48 +10:00
parent 04c5470a59
commit a47d8602bd

View File

@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 2015-2018 Danny Robson <danny@nerdcruft.net> * Copyright 2015-2019 Danny Robson <danny@nerdcruft.net>
*/ */
#include <array> #include <array>
@ -13,6 +13,31 @@
namespace cruft::adapter { namespace cruft::adapter {
namespace container { 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 <typename ContainerT>
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. /// Creates a reversed proxy for a referenced container.
/// ///
/// The target container must remain an l-value. /// The target container must remain an l-value.