VCCC  2024.05
VisualCamp Common C++ library
vector.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/12/08.
3 # */
4 #
5 # ifndef VCCC_TYPE_SUPPORT_STD_VECTOR_HPP
6 # define VCCC_TYPE_SUPPORT_STD_VECTOR_HPP
7 #
8 # include <algorithm>
9 # include <memory>
10 # include <vector>
11 
12 namespace vccc {
13 
16 
26 template<typename T, typename Allocator = std::allocator<T>>
27 std::vector<T, Allocator> reserved_vector(typename std::vector<T, Allocator>::size_type size){
28  std::vector<T, Allocator> vec;
29  vec.reserve(size);
30  return vec;
31 }
32 
45 template<typename T, typename Allocator>
46 std::vector<T, Allocator>& concat(std::vector<T, Allocator>& to, const std::vector<T, Allocator>& from) {
47  to.reserve(to.size() + from.size());
48  for(int i=0; i<from.size(); ++i)
49  to.emplace_back(from[i]);
50  return to;
51 }
52 
60 template<typename T, typename Allocator>
61 std::vector<T, Allocator>& concat(std::vector<T, Allocator>& to, std::vector<T, Allocator>&& from) {
62  to.reserve(to.size() + from.size());
63  for(int i=0; i<from.size(); ++i)
64  to.emplace_back(std::move(from[i]));
65  return to;
66 }
67 
70 
71 } // namespace vccc
72 
73 # endif // VCCC_TYPE_SUPPORT_STD_VECTOR_HPP
constexpr std::enable_if_t<(detail::ranges_to_1_tag< C, R, Args... >::value > 0), C > to(R &&r, Args &&... args)
Constructs an object of type C from the elements of r
Definition: to.hpp:446
std::vector< T, Allocator > & concat(std::vector< T, Allocator > &to, const std::vector< T, Allocator > &from)
Definition: vector.hpp:46
std::vector< T, Allocator > reserved_vector(typename std::vector< T, Allocator >::size_type size)
returns reserved vector
Definition: vector.hpp:27
Definition: directory.h:12
constexpr auto size(const C &c) -> decltype(c.size())
Definition: size.hpp:16