diff options
Diffstat (limited to 'nihil.core/construct.ccm')
| -rw-r--r-- | nihil.core/construct.ccm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nihil.core/construct.ccm b/nihil.core/construct.ccm new file mode 100644 index 0000000..5dd4422 --- /dev/null +++ b/nihil.core/construct.ccm @@ -0,0 +1,22 @@ +// This source code is released into the public domain. +export module nihil.core:construct; + +import nihil.std; + +namespace nihil { + +// A functor that constructs objects of an arbitrary type. +// Useful for std::views::transform. +template <typename T> +struct construct_fn final +{ + [[nodiscard]] auto operator()(this construct_fn const &, auto &&...args) -> T + { + return T(std::forward<decltype(args)>(args)...); + } +}; + +export template <typename T> +inline constexpr auto construct = construct_fn<T>{}; + +} // namespace nihil |
