/* OctaSTD extensions for std::vector. * * This file is part of OctaSTD. See COPYING.md for futher information. */ #ifndef OSTD_VECTOR_HH #define OSTD_VECTOR_HH #include #include #include #include "ostd/range.hh" namespace ostd { template, typename R> inline std::vector make_vector(R range, A const &alloc = A{}) { std::vector ret{alloc}; using C = range_category_t; if constexpr(std::is_convertible_v) { /* finite random access or contiguous */ auto h = range.half(); ret.reserve(range.size()); ret.insert(ret.end(), h, h + range.size()); } else { /* infinite random access and below */ for (; !range.empty(); range.pop_front()) { ret.push_back(range.front()); } } return ret; } template>> inline std::vector, A> make_vector( R &&range, A const &alloc = A{} ) { return make_vector, A>(std::forward(range), alloc); } } /* namespace ostd */ #endif