aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.util/construct.ccm
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.util/construct.ccm')
-rw-r--r--nihil.util/construct.ccm21
1 files changed, 21 insertions, 0 deletions
diff --git a/nihil.util/construct.ccm b/nihil.util/construct.ccm
new file mode 100644
index 0000000..0a0d85d
--- /dev/null
+++ b/nihil.util/construct.ccm
@@ -0,0 +1,21 @@
+// This source code is released into the public domain.
+export module nihil.util: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 {
+ 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>{};
+
+}