OpenTTD Source 20250703-master-gbf07751ee7
autorelease.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef AUTORELEASE_HPP
11#define AUTORELEASE_HPP
12
14template <auto Tfunc>
16 template <typename T>
17 constexpr void operator()(T *arg) const
18 {
19 if (arg != nullptr) Tfunc(arg);
20 }
21};
22
24template <typename T, auto Tfunc>
25using AutoRelease = std::unique_ptr<T, DeleterFromFunc<Tfunc>>;
26
27#endif /* AUTORELEASE_HPP */
std::unique_ptr< T, DeleterFromFunc< Tfunc > > AutoRelease
Specialisation of std::unique_ptr for objects which must be deleted by calling a function.
Deleter that calls a function rather than deleting the pointer.