L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
static_container
1// vi:set ft=cpp: -*- Mode: C++ -*-
2
3/* SPDX-License-Identifier: GPL-2.0-only or License-Ref-kk-custom */
4/*
5 * Copyright (C) 2012-2013 Technische Universität Dresden.
6 * Copyright (C) 2016-2017, 2020 Kernkonzept GmbH.
7 */
8
9#pragma once
10
11#include <l4/cxx/type_traits>
12#include <stddef.h>
13
14namespace cxx {
15
16template< typename T >
17class Static_container
18{
19private:
20 struct X : T
21 {
22 void *operator new (size_t, void *p) noexcept { return p; }
23 void operator delete (void *) {}
24 X() = default;
25 template<typename ...Args>
26 X(Args && ...a) : T(cxx::forward<Args>(a)...) {}
27 };
28
29public:
30 void operator = (Static_container const &) = delete;
31 Static_container(Static_container const &) = delete;
32 Static_container() = default;
33
34 T *get() { return reinterpret_cast<X*>(_s); }
35 T *operator -> () { return get(); }
36 T &operator * () { return *get(); }
37 operator T* () { return get(); }
38
39 void construct()
40 { new (reinterpret_cast<void*>(_s)) X; }
41
42 template< typename ...Args >
43 void construct(Args && ...args)
44 { new (reinterpret_cast<void*>(_s)) X(cxx::forward<Args>(args)...); }
45
46private:
47 char _s[sizeof(X)] __attribute__((aligned(__alignof(X))));
48};
49
50}
51
52
Our C++ library.
Definition arith:22