/*! @file Adapts `std::vector` for use with Hana. @copyright Louis Dionne 2013-2017 @copyright Gonzalo Brito Gadeschi 2015 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_EXT_STD_VECTOR_HPP #define BOOST_HANA_EXT_STD_VECTOR_HPP #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN namespace ext { namespace std { struct vector_tag; }} template struct tag_of> { using type = ext::std::vector_tag; }; ////////////////////////////////////////////////////////////////////////// // Comparable ////////////////////////////////////////////////////////////////////////// template <> struct equal_impl { template static bool apply(std::vector const& v1, std::vector const& v2) { return std::equal(begin(v1), end(v1), begin(v2), end(v2), hana::equal); } }; ////////////////////////////////////////////////////////////////////////// // Orderable ////////////////////////////////////////////////////////////////////////// template <> struct less_impl { template static bool apply(std::vector const& v1, std::vector const& v2) { return std::lexicographical_compare(begin(v1), end(v1), begin(v2), end(v2), hana::less); } }; #if 0 ////////////////////////////////////////////////////////////////////////// // Functor ////////////////////////////////////////////////////////////////////////// template <> struct transform_impl { template static auto apply(V&& v, F&& f) { using U = std::remove_cv_t>; using Alloc = typename std::remove_reference_t::allocator_type; using NewAlloc = typename std::allocator_traits:: template rebind_alloc; std::vector result; result.reserve(v.size()); std::transform(begin(v), end(v), std::back_inserter(result), std::forward(f)); return result; } template static auto apply(std::vector&& v, F&& f) -> std::enable_if_t< std::is_same< T, std::remove_cv_t> >{} , std::vector > { // If we receive a rvalue and the function returns elements of // the same type, we modify the vector in-place instead of // returning a new one. std::transform(std::make_move_iterator(begin(v)), std::make_move_iterator(end(v)), begin(v), std::forward(f)); return std::move(v); } }; #endif BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_EXT_STD_VECTOR_HPP