adapter: add the 'identity' adapter
This commit is contained in:
parent
04c5470a59
commit
a47d8602bd
27
adapter.hpp
27
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 <danny@nerdcruft.net>
|
||||
* Copyright 2015-2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
@ -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 <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.
|
||||
///
|
||||
/// The target container must remain an l-value.
|
||||
|
Loading…
Reference in New Issue
Block a user