2014-09-27 18:24:44 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
*
|
|
|
|
* This file is part of InspIRCd. InspIRCd 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.
|
|
|
|
*
|
|
|
|
* This program 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. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace insp
|
|
|
|
{
|
|
|
|
template <typename T> class aligned_storage;
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:16:57 +00:00
|
|
|
/** A block of preallocated memory which an object can be created into. */
|
2014-09-27 18:24:44 +02:00
|
|
|
template <typename T>
|
2021-03-02 03:05:42 +00:00
|
|
|
class insp::aligned_storage final
|
2014-09-27 18:24:44 +02:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2021-03-02 03:05:42 +00:00
|
|
|
/** The underlying aligned storage block. */
|
2024-06-04 13:13:29 +01:00
|
|
|
alignas(T) mutable std::byte data[sizeof(T)];
|
2014-09-27 18:24:44 +02:00
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2021-03-02 03:05:42 +00:00
|
|
|
/** Default constructor for the aligned_storage class. */
|
2020-11-01 02:22:41 +00:00
|
|
|
aligned_storage() = default;
|
2014-09-27 18:24:44 +02:00
|
|
|
|
2021-03-02 03:05:42 +00:00
|
|
|
/** Ignores copying via the copy constructor. */
|
|
|
|
aligned_storage(const aligned_storage&) { }
|
2014-09-27 18:24:44 +02:00
|
|
|
|
2021-03-02 03:05:42 +00:00
|
|
|
/** Accessor for the underlying aligned storage block. */
|
|
|
|
T* operator->() const { return static_cast<T*>(static_cast<void*>(&data)); }
|
2014-09-27 18:24:44 +02:00
|
|
|
|
2021-03-02 03:05:42 +00:00
|
|
|
/** Constant accessor for the underlying aligned storage block. */
|
|
|
|
operator T*() const { return operator->(); }
|
2014-09-27 18:24:44 +02:00
|
|
|
};
|