void_ptr.h
Go to the documentation of this file.
1
/*
2
* Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3
*/
4
5
#pragma once
6
7
#include <memory>
8
11
namespace
mc_rtc
12
{
13
14
using
void_ptr
= std::unique_ptr<void, void (*)(
void
*)>;
15
17
template
<
typename
T,
typename
... Args>
18
void_ptr
make_void_ptr
(Args &&... args)
19
{
20
return
{
new
T(std::forward<Args>(args)...), [](
void
* ptr) {
delete
static_cast<
T *
>
(ptr); }};
21
}
22
24
template
<
typename
T>
25
void_ptr
make_void_ptr
(std::unique_ptr<T> ptr)
26
{
27
return
{ptr.release(), [](
void
* ptr) {
delete
static_cast<
T *
>
(ptr); }};
28
}
29
31
template
<
typename
T>
32
struct
void_ptr_caster
33
{
34
T *
operator()
(
void_ptr
& ptr) {
return
static_cast<
T *
>
(ptr.get()); }
35
36
const
T *
operator()
(
const
void_ptr
& ptr) {
return
static_cast<
const
T *
>
(ptr.get()); }
37
};
38
39
}
// namespace mc_rtc
mc_rtc::void_ptr_caster::operator()
T * operator()(void_ptr &ptr)
Definition:
void_ptr.h:34
mc_rtc::void_ptr
std::unique_ptr< void, void(*)(void *)> void_ptr
Definition:
void_ptr.h:14
mc_rtc::make_void_ptr
void_ptr make_void_ptr(Args &&... args)
Definition:
void_ptr.h:18
mc_rtc::void_ptr_caster::operator()
const T * operator()(const void_ptr &ptr)
Definition:
void_ptr.h:36
mc_rtc::void_ptr_caster
Definition:
void_ptr.h:32
mc_rtc
Definition:
Contact.h:87
include
mc_rtc
void_ptr.h
Generated by
1.8.17