functor: add construct and tuple_construct
This commit is contained in:
parent
a2592edc53
commit
e7dda93a36
34
functor.hpp
34
functor.hpp
@ -3,12 +3,13 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/.
|
* 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
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
|
||||||
namespace cruft::functor {
|
namespace cruft::functor {
|
||||||
@ -69,4 +70,33 @@ namespace cruft::functor {
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
template <typename ValueT>
|
template <typename ValueT>
|
||||||
constant (ValueT) -> constant<std::decay_t<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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user