Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / include / xbt / memory.hpp
1 /* Copyright (c) 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRIX_XBT_MEMORY_HPP
8 #define SIMGRIX_XBT_MEMORY_HPP
9
10 #include <memory>
11
12 namespace simgrid {
13 namespace xbt {
14
15 /** Delete operator which call a `destroy()` free function */
16 template<class T>
17 struct destroy_delete {
18   void operator()(T* t) const
19   {
20     destroy(t);
21   }
22 };
23
24 /** A `unique_ptr` which works for SimGrid C types (dynar, swag, automaton, etc.)
25  *
26  *  It uses an overloaded `destroy()` function to delete the object.
27  */
28 template<class T>
29 using unique_ptr = std::unique_ptr<T, destroy_delete<T> >;
30
31 }
32 }
33
34 #endif