aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.util
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-07-01 19:18:42 +0100
committerLexi Winter <lexi@le-fay.org>2025-07-01 19:18:42 +0100
commit378dd663a402fe196f2b56c6413eb3f623aecbbf (patch)
tree6d13f14ff8f9bff7c55a30eb046af489d0f677a2 /nihil.util
parent2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 (diff)
downloadnihil-378dd663a402fe196f2b56c6413eb3f623aecbbf.tar.gz
nihil-378dd663a402fe196f2b56c6413eb3f623aecbbf.tar.bz2
cli: refactoring
Diffstat (limited to 'nihil.util')
-rw-r--r--nihil.util/CMakeLists.txt1
-rw-r--r--nihil.util/construct.ccm21
-rw-r--r--nihil.util/nihil.util.ccm1
3 files changed, 23 insertions, 0 deletions
diff --git a/nihil.util/CMakeLists.txt b/nihil.util/CMakeLists.txt
index 109e4d4..2fb5111 100644
--- a/nihil.util/CMakeLists.txt
+++ b/nihil.util/CMakeLists.txt
@@ -12,6 +12,7 @@ target_sources(nihil.util
nihil.util.ccm
capture_stream.ccm
+ construct.ccm
ctype.ccm
parse_size.ccm
next_word.ccm
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>{};
+
+}
diff --git a/nihil.util/nihil.util.ccm b/nihil.util/nihil.util.ccm
index d8628a4..132978e 100644
--- a/nihil.util/nihil.util.ccm
+++ b/nihil.util/nihil.util.ccm
@@ -2,6 +2,7 @@
export module nihil.util;
export import :capture_stream;
+export import :construct;
export import :ctype;
export import :parse_size;
export import :next_word;