diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:19:23 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:19:23 +0100 |
| commit | a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df (patch) | |
| tree | 6dafcf2674780649dcdc2649855722357837a68e /nihil.posix/posix.argv.ccm | |
| parent | 4fa6821e0645ff61a9380cd090abff472205c630 (diff) | |
| download | nihil-a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df.tar.gz nihil-a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df.tar.bz2 | |
wip macOS port
Diffstat (limited to 'nihil.posix/posix.argv.ccm')
| -rw-r--r-- | nihil.posix/posix.argv.ccm | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/nihil.posix/posix.argv.ccm b/nihil.posix/posix.argv.ccm deleted file mode 100644 index 6f60f4b..0000000 --- a/nihil.posix/posix.argv.ccm +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This source code is released into the public domain. - */ - -module; - -#include <memory> -#include <ranges> -#include <string> -#include <vector> - -export module nihil.posix:argv; - -namespace nihil { - -/* - * argv: stores a null-terminated array of nul-terminated C strings. - * argv::data() is suitable for passing to ::execv(). - * - * Create an argv using argv::from_range(), which takes a range of - * string-like objects. - */ - -export struct argv { - /* - * Create a new argv from a range. - */ - argv(std::from_range_t, std::ranges::range auto &&args) - { - for (auto &&arg : args) - add_arg(std::string_view(arg)); - - m_args.push_back(nullptr); - } - - /* - * Create an argv from an initializer list. - */ - template<typename T> - explicit argv(std::initializer_list<T> &&args) - : argv(std::from_range, std::forward<decltype(args)>(args)) - { - } - - // Movable. - argv(argv &&) noexcept; - auto operator=(this argv &, argv &&other) -> argv &; - - // Not copyable. TODO: for completeness, it probably should be. - argv(argv const &) = delete; - auto operator=(this argv &, argv const &other) -> argv& = delete; - - ~argv(); - - // Access the stored arguments. - [[nodiscard]] auto data(this argv const &self) -> char const * const *; - [[nodiscard]] auto data(this argv &self) -> char * const *; - [[nodiscard]] auto size(this argv const &self); - - // Range access - [[nodiscard]] auto begin(this argv const &self); - [[nodiscard]] auto end(this argv const &self); - -private: - // Use the from_range() factory method to create new instances. - argv(); - - // The argument pointers, including the null terminator. - // This can't be a vector<unique_ptr> because we need an array of - // char pointers to pass to exec. - std::vector<char *> m_args; - - // Add a new argument to the array. - auto add_arg(this argv &self, std::string_view arg) -> void; -}; - -} // namespace nihil - |
