From 1b0853a9c542d3ad1fc6d8a9ccac6bbdecc26503 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 3 Apr 2019 17:16:43 -0700 Subject: [PATCH] ircd::util: Split custom_ptr; make strong type; pointer conversion. --- include/ircd/util/custom_ptr.h | 34 ++++++++++++++++++++++++++++++++++ include/ircd/util/util.h | 8 +------- 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 include/ircd/util/custom_ptr.h diff --git a/include/ircd/util/custom_ptr.h b/include/ircd/util/custom_ptr.h new file mode 100644 index 000000000..7a3a9ea9b --- /dev/null +++ b/include/ircd/util/custom_ptr.h @@ -0,0 +1,34 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2019 Jason Volk +// +// 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 struct custom_ptr; +} + +template +struct ircd::util::custom_ptr +:std::unique_ptr> +{ + operator T *() const; + + using std::unique_ptr>::unique_ptr; +}; + +template +ircd::util::custom_ptr::operator +T *() +const +{ + return this->get(); +} diff --git a/include/ircd/util/util.h b/include/ircd/util/util.h index 53571a5a1..10b9b4c15 100644 --- a/include/ircd/util/util.h +++ b/include/ircd/util/util.h @@ -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 -using custom_ptr = std::unique_ptr>; - // // Misc size() participants. //