| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // | 56 // |
| 57 // void Foo(const std::vector<std::string>& input) | 57 // void Foo(const std::vector<std::string>& input) |
| 58 // { | 58 // { |
| 59 // WebVector<WebCString> cstrings = input; | 59 // WebVector<WebCString> cstrings = input; |
| 60 // ... | 60 // ... |
| 61 // } | 61 // } |
| 62 // | 62 // |
| 63 template <typename T> | 63 template <typename T> |
| 64 class WebVector { | 64 class WebVector { |
| 65 public: | 65 public: |
| 66 typedef T ValueType; | 66 using ValueType = T; |
| 67 using iterator = T*; |
| 68 using const_iterator = const T*; |
| 67 | 69 |
| 68 ~WebVector() | 70 ~WebVector() |
| 69 { | 71 { |
| 70 destroy(); | 72 destroy(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 explicit WebVector(size_t size = 0) | 75 explicit WebVector(size_t size = 0) |
| 74 { | 76 { |
| 75 initialize(size); | 77 initialize(size); |
| 76 } | 78 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 for (size_t i = 0; i < m_size; i++) { | 141 for (size_t i = 0; i < m_size; i++) { |
| 140 if (m_ptr[i] == value) | 142 if (m_ptr[i] == value) |
| 141 return true; | 143 return true; |
| 142 } | 144 } |
| 143 return false; | 145 return false; |
| 144 } | 146 } |
| 145 | 147 |
| 146 T* data() { return m_ptr; } | 148 T* data() { return m_ptr; } |
| 147 const T* data() const { return m_ptr; } | 149 const T* data() const { return m_ptr; } |
| 148 | 150 |
| 151 iterator begin() { return data(); } |
| 152 iterator end() { return begin() + m_size; } |
| 153 const_iterator begin() const { return data(); } |
| 154 const_iterator end() const { return begin() + m_size; } |
| 155 |
| 149 void swap(WebVector<T>& other) | 156 void swap(WebVector<T>& other) |
| 150 { | 157 { |
| 151 std::swap(m_ptr, other.m_ptr); | 158 std::swap(m_ptr, other.m_ptr); |
| 152 std::swap(m_size, other.m_size); | 159 std::swap(m_size, other.m_size); |
| 153 } | 160 } |
| 154 | 161 |
| 155 private: | 162 private: |
| 156 void initialize(size_t size) | 163 void initialize(size_t size) |
| 157 { | 164 { |
| 158 validateSize(size); | 165 validateSize(size); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ::operator delete(m_ptr); | 200 ::operator delete(m_ptr); |
| 194 } | 201 } |
| 195 | 202 |
| 196 T* m_ptr; | 203 T* m_ptr; |
| 197 size_t m_size; | 204 size_t m_size; |
| 198 }; | 205 }; |
| 199 | 206 |
| 200 } // namespace blink | 207 } // namespace blink |
| 201 | 208 |
| 202 #endif | 209 #endif |
| OLD | NEW |