deleter.hh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Deleter objects
  2. Copyright (C) 2020-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef CC1_PLUGIN_DELETER_HH
  16. #define CC1_PLUGIN_DELETER_HH
  17. #include <memory>
  18. namespace cc1_plugin
  19. {
  20. // Any pointer type requires a deleter object that knows how to
  21. // clean up. These are used in multiple places.
  22. template<typename T> struct deleter;
  23. template<>
  24. struct deleter<char>
  25. {
  26. void operator() (char *s)
  27. {
  28. delete[] s;
  29. }
  30. };
  31. template<>
  32. struct deleter<gcc_type_array>
  33. {
  34. void operator() (gcc_type_array *p)
  35. {
  36. delete[] p->elements;
  37. delete p;
  38. }
  39. };
  40. template<typename T> using unique_ptr = std::unique_ptr<T, deleter<T>>;
  41. }
  42. #endif // CC1_PLUGIN_DELETER_HH