]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/cxx/lib/tl/include/static_container
Update
[l4.git] / l4 / pkg / l4re-core / cxx / lib / tl / include / static_container
1 // vi:ft=cpp
2
3 #pragma once
4
5 #include <new>
6 #include <l4/cxx/type_traits>
7
8 namespace cxx {
9
10 template< typename T >
11 class Static_container
12 {
13 public:
14   void operator = (Static_container const &) = delete;
15   Static_container(Static_container const &) = delete;
16   Static_container() = default;
17
18   T *get() { return reinterpret_cast<T*>(_s); }
19   T *operator -> () { return get(); }
20   T &operator * () { return *get(); }
21   operator T* () { return get(); }
22
23   void construct()
24   { new (reinterpret_cast<void*>(_s)) T; }
25
26   template< typename ...Args >
27   void construct(Args... args)
28   { new (reinterpret_cast<void*>(_s)) T(cxx::forward<Args>(args)...); }
29
30 private:
31   char _s[sizeof(T)] __attribute__((aligned(__alignof(T))));
32 };
33
34 }
35
36