OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_MEMORY_FREE_DELETER_H_ |
| 6 #define BASE_MEMORY_FREE_DELETER_H_ |
| 7 |
| 8 #include <stdlib.h> |
| 9 |
| 10 namespace base { |
| 11 |
| 12 // Function object which invokes 'free' on its parameter, which must be |
| 13 // a pointer. Can be used to store malloc-allocated pointers in std::unique_ptr: |
| 14 // |
| 15 // std::unique_ptr<int, base::FreeDeleter> foo_ptr( |
| 16 // static_cast<int*>(malloc(sizeof(int)))); |
| 17 struct FreeDeleter { |
| 18 inline void operator()(void* ptr) const { |
| 19 free(ptr); |
| 20 } |
| 21 }; |
| 22 |
| 23 } // namespace base |
| 24 |
| 25 #endif // BASE_MEMORY_FREE_DELETER_H_ |
OLD | NEW |