diff --git a/src/containers.hh b/src/containers.hh index 9597a25b..b0fc58e3 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -22,19 +22,26 @@ template struct ReverseView { using iterator = decltype(std::declval().rbegin()); - ReverseView(Container& container) : m_container(container) {} iterator begin() { return m_container.rbegin(); } iterator end() { return m_container.rend(); } -private: - Container& m_container; + Container m_container; }; +template +using RemoveReference = typename std::remove_reference::type; + struct ReverseFactory { template - ReverseView operator()(Container&& container) const + ReverseView> operator()(Container&& container) const + { + return {std::move(container)}; + } + + template + ReverseView operator()(Container& container) const { return {container}; } @@ -84,14 +91,10 @@ struct FilterView const FilterView& m_view; }; - FilterView(Container& container, Filter filter) - : m_container(container), m_filter(std::move(filter)) {} - Iterator begin() const { return {*this, m_container.begin(), m_container.end()}; } Iterator end() const { return {*this, m_container.end(), m_container.end()}; } -private: - Container& m_container; + Container m_container; Filter m_filter; }; @@ -99,7 +102,10 @@ template struct FilterFactory { template - FilterView operator()(Container&& container) const { return {container, std::move(m_filter)}; } + FilterView operator()(Container& container) const { return {container, std::move(m_filter)}; } + + template + FilterView, Filter> operator()(Container&& container) const { return {std::move(container), std::move(m_filter)}; } Filter m_filter; }; @@ -142,14 +148,10 @@ struct TransformView const TransformView& m_view; }; - TransformView(Container& container, Transform transform) - : m_container(container), m_transform(std::move(transform)) {} - Iterator begin() const { return {*this, m_container.begin()}; } Iterator end() const { return {*this, m_container.end()}; } -private: - Container& m_container; + Container m_container; Transform m_transform; }; @@ -157,7 +159,10 @@ template struct TransformFactory { template - TransformView operator()(Container&& container) const { return {container, std::move(m_transform)}; } + TransformView operator()(Container& container) const { return {container, std::move(m_transform)}; } + + template + TransformView, Transform> operator()(Container&& container) const { return {std::move(container), std::move(m_transform)}; } Transform m_transform; }; @@ -166,7 +171,6 @@ template inline ContainerView> transform(Transform t) { return {{std::move(t)}}; } - template struct ConcatView {