mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd::util: Split custom_ptr; make strong type; pointer conversion.
This commit is contained in:
parent
8e1dc9f453
commit
1b0853a9c5
2 changed files with 35 additions and 7 deletions
34
include/ircd/util/custom_ptr.h
Normal file
34
include/ircd/util/custom_ptr.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_UTIL_CUSTOM_PTR_H
|
||||
|
||||
namespace ircd::util
|
||||
{
|
||||
template<class T> struct custom_ptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct ircd::util::custom_ptr
|
||||
:std::unique_ptr<T, std::function<void (T *)>>
|
||||
{
|
||||
operator T *() const;
|
||||
|
||||
using std::unique_ptr<T, std::function<void (T *)>>::unique_ptr;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
ircd::util::custom_ptr<T>::operator
|
||||
T *()
|
||||
const
|
||||
{
|
||||
return this->get();
|
||||
}
|
|
@ -35,6 +35,7 @@ namespace ircd
|
|||
#include "unwind.h"
|
||||
#include "reentrance.h"
|
||||
#include "enum.h"
|
||||
#include "custom_ptr.h"
|
||||
#include "syscall.h"
|
||||
#include "env.h"
|
||||
#include "va_rtti.h"
|
||||
|
@ -63,13 +64,6 @@ namespace ircd
|
|||
namespace ircd {
|
||||
namespace util {
|
||||
|
||||
/// A standard unique_ptr but accepting an std::function for T as its custom
|
||||
/// deleter. This reduces the boilerplate burden on declaring the right
|
||||
/// unique_ptr template for custom deleters every single time.
|
||||
///
|
||||
template<class T>
|
||||
using custom_ptr = std::unique_ptr<T, std::function<void (T *)>>;
|
||||
|
||||
//
|
||||
// Misc size() participants.
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue