File indexing completed on 2025-01-18 09:37:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_HANA_EXT_STD_VECTOR_HPP
0012 #define BOOST_HANA_EXT_STD_VECTOR_HPP
0013
0014 #include <boost/hana/config.hpp>
0015 #include <boost/hana/equal.hpp>
0016 #include <boost/hana/fwd/core/tag_of.hpp>
0017 #include <boost/hana/less.hpp>
0018
0019 #include <algorithm>
0020 #include <iterator>
0021 #include <memory>
0022 #include <type_traits>
0023 #include <utility>
0024 #include <vector>
0025
0026
0027 namespace boost { namespace hana {
0028 namespace ext { namespace std { struct vector_tag; }}
0029
0030 template <typename T, typename Allocator>
0031 struct tag_of<std::vector<T, Allocator>> {
0032 using type = ext::std::vector_tag;
0033 };
0034
0035
0036
0037
0038 template <>
0039 struct equal_impl<ext::std::vector_tag, ext::std::vector_tag> {
0040 template <typename T1, typename A1, typename T2, typename A2>
0041 static bool apply(std::vector<T1, A1> const& v1,
0042 std::vector<T2, A2> const& v2)
0043 {
0044 return std::equal(begin(v1), end(v1),
0045 begin(v2), end(v2),
0046 hana::equal);
0047 }
0048 };
0049
0050
0051
0052
0053 template <>
0054 struct less_impl<ext::std::vector_tag, ext::std::vector_tag> {
0055 template <typename T1, typename A1, typename T2, typename A2>
0056 static bool apply(std::vector<T1, A1> const& v1,
0057 std::vector<T2, A2> const& v2)
0058 {
0059 return std::lexicographical_compare(begin(v1), end(v1),
0060 begin(v2), end(v2),
0061 hana::less);
0062 }
0063 };
0064
0065 #if 0
0066
0067
0068
0069 template <>
0070 struct transform_impl<ext::std::vector_tag> {
0071 template <typename V, typename F>
0072 static auto apply(V&& v, F&& f) {
0073 using U = std::remove_cv_t<std::remove_reference_t<
0074 decltype(f(*v.begin()))
0075 >>;
0076 using Alloc = typename std::remove_reference_t<V>::allocator_type;
0077 using NewAlloc = typename std::allocator_traits<Alloc>::
0078 template rebind_alloc<U>;
0079 std::vector<U, NewAlloc> result; result.reserve(v.size());
0080
0081 std::transform(begin(v), end(v),
0082 std::back_inserter(result), std::forward<F>(f));
0083 return result;
0084 }
0085
0086 template <typename T, typename Alloc, typename F>
0087 static auto apply(std::vector<T, Alloc>&& v, F&& f)
0088 -> std::enable_if_t<
0089 std::is_same<
0090 T,
0091 std::remove_cv_t<std::remove_reference_t<
0092 decltype(f(*v.begin()))
0093 >>
0094 >{}
0095 , std::vector<T, Alloc>
0096 >
0097 {
0098
0099
0100
0101 std::transform(std::make_move_iterator(begin(v)),
0102 std::make_move_iterator(end(v)),
0103 begin(v), std::forward<F>(f));
0104 return std::move(v);
0105 }
0106 };
0107 #endif
0108 }}
0109
0110 #endif