• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FRUIT_FIXED_SIZE_VECTOR_TEMPLATES_H
18 #define FRUIT_FIXED_SIZE_VECTOR_TEMPLATES_H
19 
20 #if !IN_FRUIT_CPP_FILE
21 #error "Fruit .template.h file included in non-cpp file."
22 #endif
23 
24 #include <fruit/impl/data_structures/fixed_size_vector.h>
25 
26 #include <fruit/impl/fruit_assert.h>
27 
28 namespace fruit {
29 namespace impl {
30 
31 template <typename T, typename Allocator>
FixedSizeVector(const FixedSizeVector & other,std::size_t capacity)32 FixedSizeVector<T, Allocator>::FixedSizeVector(const FixedSizeVector& other, std::size_t capacity)
33     : FixedSizeVector(capacity, other.allocator) {
34   FruitAssert(other.size() <= capacity);
35   // This is not just an optimization, we also want to make sure that other.capacity (and therefore
36   // also this.capacity) is >0, or we'd pass nullptr to memcpy (although with a size of 0).
37   if (other.size() != 0) {
38     FruitAssert(v_begin != nullptr);
39     FruitAssert(other.v_begin != nullptr);
40     std::memcpy(v_begin, other.v_begin, other.size() * sizeof(T));
41   }
42   v_end = v_begin + other.size();
43 }
44 
45 template <typename T, typename Allocator>
FixedSizeVector(std::size_t size,const T & value,Allocator allocator)46 FixedSizeVector<T, Allocator>::FixedSizeVector(std::size_t size, const T& value, Allocator allocator)
47     : FixedSizeVector(size, allocator) {
48   for (std::size_t i = 0; i < size; ++i) {
49     push_back(value);
50   }
51 }
52 
53 } // namespace impl
54 } // namespace fruit
55 
56 #endif // FRUIT_FIXED_SIZE_VECTOR_TEMPLATES_H
57