alpaqa 1.0.0a8
Nonconvex constrained optimization
Loading...
Searching...
No Matches
options.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <memory>
6#include <span>
7#include <string_view>
8#include <vector>
9
10class Options {
11 private:
12 std::vector<std::string_view> options_storage;
13 std::unique_ptr<bool[]> used_storage;
14
15 public:
16 Options(int argc, const char *const argv[]) {
17 std::copy(argv, argv + argc, std::back_inserter(options_storage));
18 used_storage = std::make_unique<bool[]>(options_storage.size());
19 }
20 [[nodiscard]] std::span<const std::string_view> options() const {
21 return options_storage;
22 }
23 [[nodiscard]] std::span<bool> used() {
24 return std::span{used_storage.get(), options_storage.size()};
25 }
26};
27
28template <class T>
29decltype(auto) set_params(T &t, std::string_view prefix, Options &opts) {
30 return alpaqa::params::set_params(t, prefix, opts.options(), opts.used());
31}
std::span< const std::string_view > options() const
Definition: options.hpp:20
std::span< bool > used()
Definition: options.hpp:23
std::vector< std::string_view > options_storage
Definition: options.hpp:12
Options(int argc, const char *const argv[])
Definition: options.hpp:16
std::unique_ptr< bool[]> used_storage
Definition: options.hpp:13
void set_params(T &t, std::string_view prefix, std::span< const std::string_view > options, std::optional< std::span< bool > > used=std::nullopt)
Overwrites t based on the options that start with prefix.
Definition: params.hpp:49
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition: options.hpp:29