util/VarSize: convert static_assert to concept check
This commit is contained in:
parent
c96e8ab47c
commit
1448f52eac
@ -1,8 +1,7 @@
|
|||||||
// SPDX-License-Identifier: BSD-2-Clause
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
// author: Max Kellermann <max.kellermann@gmail.com>
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
||||||
|
|
||||||
#ifndef MPD_VAR_SIZE_HXX
|
#pragma once
|
||||||
#define MPD_VAR_SIZE_HXX
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -21,13 +20,11 @@
|
|||||||
* #T
|
* #T
|
||||||
*/
|
*/
|
||||||
template<class T, typename... Args>
|
template<class T, typename... Args>
|
||||||
|
requires std::is_standard_layout_v<T>
|
||||||
[[gnu::malloc]] [[gnu::returns_nonnull]]
|
[[gnu::malloc]] [[gnu::returns_nonnull]]
|
||||||
T *
|
T *
|
||||||
NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
|
NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
|
||||||
{
|
{
|
||||||
static_assert(std::is_standard_layout<T>::value,
|
|
||||||
"Not standard-layout");
|
|
||||||
|
|
||||||
/* determine the total size of this instance */
|
/* determine the total size of this instance */
|
||||||
size_t size = sizeof(T) - declared_tail_size + real_tail_size;
|
size_t size = sizeof(T) - declared_tail_size + real_tail_size;
|
||||||
|
|
||||||
@ -53,5 +50,3 @@ DeleteVarSize(T *instance)
|
|||||||
/* free memory */
|
/* free memory */
|
||||||
free(instance);
|
free(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user