base: Add 'construct_at' utility

This utility allows for the manual placement of objects without the need
to have a global placement new operation nor the need for type-specific
new operators.

Issue #989
This commit is contained in:
Norman Feske
2014-02-07 14:49:21 +01:00
parent cdb5030cbb
commit 6f9e15aff8
4 changed files with 131 additions and 16 deletions

View File

@ -14,6 +14,7 @@
#ifndef _INCLUDE__UTIL__VOLATILE_OBJECT_H_
#define _INCLUDE__UTIL__VOLATILE_OBJECT_H_
#include <util/construct_at.h>
#include <base/printf.h>
#include <base/stdint.h>
@ -39,21 +40,6 @@ class Genode::Volatile_object
{
private:
/**
* Utility to equip an existing type 'T' with a placement new operator
*/
template <typename T>
struct Placeable : T
{
template <typename... ARGS>
Placeable(ARGS &&... args)
:
T(args...)
{ }
void *operator new (size_t, void *ptr) { return ptr; }
};
/**
* Static reservation of memory for the embedded object
*/
@ -66,7 +52,7 @@ class Genode::Volatile_object
template <typename... ARGS> void _do_construct(ARGS &&... args)
{
new (_space) Placeable<MT>(args...);
construct_at<MT>(_space, args...);
_constructed = true;
}