functor: add construct and tuple_construct

This commit is contained in:
Danny Robson 2019-02-05 12:13:53 +11:00
parent a2592edc53
commit e7dda93a36

View File

@ -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 <danny@nerdcruft.net>
* Copyright 2018-2019 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include <utility>
#include <tuple>
namespace cruft::functor {
@ -69,4 +70,33 @@ namespace cruft::functor {
//-------------------------------------------------------------------------
template <typename ValueT>
constant (ValueT) -> constant<std::decay_t<ValueT>>;
};
///////////////////////////////////////////////////////////////////////////
/// Returns a ValueT constructed from the supplied arguments.
template <typename ValueT>
struct construct {
template <typename ...Args>
ValueT operator() (Args &&...args)
{
return ValueT {
std::forward<Args> (args)...
};
}
};
///------------------------------------------------------------------------
/// Returns a ValueT constructed from a tuple of arguments.
template <typename ValueT>
struct tuple_construct {
template <typename Args>
ValueT operator() (Args &&args)
{
return std::apply (
construct<ValueT> {},
std::forward<Args> (args)
);
}
};
}