-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
{
}
+Args::Args(std::initializer_list<std::string> init) noexcept
+{
+ m_args.assign(init.begin(), init.end());
+}
+
Args
Args::from_argv(int argc, const char* const* argv)
{
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include <deque>
#include <filesystem>
+#include <initializer_list>
#include <optional>
#include <string>
#include <string_view>
};
Args() = default;
+ Args(std::initializer_list<std::string>) noexcept;
Args(const Args& other) = default;
Args(Args&& other) noexcept;
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
CHECK(args.size() == 0);
}
-TEST_CASE("Args copy constructor")
+TEST_CASE("Args initializer list constructor")
{
- Args args1;
- args1.push_back("foo");
- args1.push_back("bar");
+ Args args{"foo", "bar"};
+ CHECK(args.size() == 2);
+ CHECK(args[0] == "foo");
+ CHECK(args[1] == "bar");
+}
+TEST_CASE("Args copy constructor")
+{
+ Args args1{"foo", "bar"};
Args args2(args1);
CHECK(args1 == args2);
}
TEST_CASE("Args move constructor")
{
- Args args1;
- args1.push_back("foo");
- args1.push_back("bar");
+ Args args1{"foo", "bar"};
const char* foo_pointer = args1[0].c_str();
const char* bar_pointer = args1[1].c_str();