From e7dda93a36bc1f68f6d1b231e8da1c70daff80bb Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 5 Feb 2019 12:13:53 +1100 Subject: [PATCH] functor: add construct and tuple_construct --- functor.hpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/functor.hpp b/functor.hpp index 8ad31dfb..9b0e4f85 100644 --- a/functor.hpp +++ b/functor.hpp @@ -3,12 +3,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2018 Danny Robson + * Copyright 2018-2019 Danny Robson */ #pragma once #include +#include namespace cruft::functor { @@ -69,4 +70,33 @@ namespace cruft::functor { //------------------------------------------------------------------------- template constant (ValueT) -> constant>; -}; \ No newline at end of file + + + /////////////////////////////////////////////////////////////////////////// + /// Returns a ValueT constructed from the supplied arguments. + template + struct construct { + template + ValueT operator() (Args &&...args) + { + return ValueT { + std::forward (args)... + }; + } + }; + + + ///------------------------------------------------------------------------ + /// Returns a ValueT constructed from a tuple of arguments. + template + struct tuple_construct { + template + ValueT operator() (Args &&args) + { + return std::apply ( + construct {}, + std::forward (args) + ); + } + }; +} \ No newline at end of file