From 8badffee795d4ceb53748a76444084e8e2594bbc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 31 Dec 2015 21:56:33 +0100 Subject: [PATCH] construct: change return type of cons() from EbmlMaster* to T* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's really no need to use the generic parent type. Using the template argument's type instead allows one to wrap the result into shared pointers as in e.g. KaxAttachedPtr createAttachment() { // … return { mtx::construct::cons(new KaxFile, …) }; } --- src/common/construct.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/construct.h b/src/common/construct.h index 904a124f0..081c0487a 100644 --- a/src/common/construct.h +++ b/src/common/construct.h @@ -139,9 +139,9 @@ cons_impl(EbmlMaster *master, } template -EbmlMaster * -master() { - T *master = new T; +auto +master() -> T * { + auto *master = new T; for (auto element : *master) delete element; master->RemoveAll(); @@ -149,15 +149,15 @@ master() { } template -inline EbmlMaster * -cons() { +inline auto +cons() -> Tmaster * { return master(); } template -inline EbmlMaster * -cons(Targs... args) { +inline auto +cons(Targs... args) -> Tmaster * { auto master = cons(); cons_impl(master, args...);