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_ARENA_ALLOCATOR_DEFN_H
18 #define FRUIT_ARENA_ALLOCATOR_DEFN_H
19 
20 #include <fruit/impl/data_structures/arena_allocator.h>
21 
22 namespace fruit {
23 namespace impl {
24 
25 template <typename T>
ArenaAllocator(MemoryPool & memory_pool)26 inline ArenaAllocator<T>::ArenaAllocator(MemoryPool& memory_pool) : pool(&memory_pool) {}
27 
28 template <typename T>
29 template <typename U>
ArenaAllocator(const ArenaAllocator<U> & other)30 inline ArenaAllocator<T>::ArenaAllocator(const ArenaAllocator<U>& other) : pool(other.pool) {}
31 
32 template <typename T>
allocate(std::size_t n)33 inline T* ArenaAllocator<T>::allocate(std::size_t n) {
34   return pool->allocate<T>(n);
35 }
36 
37 template <typename T>
deallocate(T *,std::size_t)38 void ArenaAllocator<T>::deallocate(T*, std::size_t) {
39   // Intentionally empty, the memory will be deallocated when the MemoryPool is destroyed.
40 }
41 
42 template <class T, class U>
43 bool operator==(const ArenaAllocator<T>& x, const ArenaAllocator<U>& y) {
44   return x.pool == y.pool;
45 }
46 
47 template <class T, class U>
48 bool operator!=(const ArenaAllocator<T>& x, const ArenaAllocator<U>& y) {
49   return x.pool != y.pool;
50 }
51 
52 } // namespace impl
53 } // namespace fruit
54 
55 #endif // FRUIT_ARENA_ALLOCATOR_DEFN_H
56