1 /* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef MEM_ROOT_DEQUE_H 24 #define MEM_ROOT_DEQUE_H 25 26 #include <deque> 27 #include <initializer_list> 28 #include <utility> 29 30 #include "sql/mem_root_allocator.h" 31 32 /// A utility for having an std::deque which stores its elements on a MEM_ROOT. 33 template <class T> 34 class mem_root_deque : public std::deque<T, Mem_root_allocator<T>> { 35 private: 36 using super = std::deque<T, Mem_root_allocator<T>>; 37 38 public: mem_root_deque(MEM_ROOT * mem_root)39 explicit mem_root_deque(MEM_ROOT *mem_root) 40 : super(Mem_root_allocator<T>(mem_root)) {} 41 mem_root_deque(typename super::size_type count,const T & value,MEM_ROOT * mem_root)42 mem_root_deque(typename super::size_type count, const T &value, 43 MEM_ROOT *mem_root) 44 : super(count, value, Mem_root_allocator<T>(mem_root)) {} 45 mem_root_deque(typename super::size_type count,MEM_ROOT * mem_root)46 mem_root_deque(typename super::size_type count, MEM_ROOT *mem_root) 47 : super(count, Mem_root_allocator<T>(mem_root)) {} 48 49 template <class InputIt> mem_root_deque(InputIt first,InputIt last,MEM_ROOT * mem_root)50 mem_root_deque(InputIt first, InputIt last, MEM_ROOT *mem_root) 51 : super(first, last, Mem_root_allocator<T>(mem_root)) {} 52 mem_root_deque(const mem_root_deque & other)53 mem_root_deque(const mem_root_deque &other) : super(other) {} mem_root_deque(const mem_root_deque & other,MEM_ROOT * mem_root)54 mem_root_deque(const mem_root_deque &other, MEM_ROOT *mem_root) 55 : super(other, Mem_root_allocator<T>(mem_root)) {} 56 mem_root_deque(mem_root_deque && other)57 mem_root_deque(mem_root_deque &&other) : super(std::move(other)) {} mem_root_deque(mem_root_deque && other,MEM_ROOT * mem_root)58 mem_root_deque(mem_root_deque &&other, MEM_ROOT *mem_root) 59 : super(std::move(other), Mem_root_allocator<T>(mem_root)) {} 60 mem_root_deque(std::initializer_list<T> init,MEM_ROOT * mem_root)61 mem_root_deque(std::initializer_list<T> init, MEM_ROOT *mem_root) 62 : super(std::move(init), Mem_root_allocator<T>(mem_root)) {} 63 64 mem_root_deque &operator=(const mem_root_deque &arg) = default; 65 }; 66 67 #endif // MEM_ROOT_DEQUE_H 68