alpaqa 1.0.0a12
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::vector<unsigned> 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.resize(options_storage.size());
19 }
20 [[nodiscard]] std::span<const std::string_view> options() const {
21 return options_storage;
22 }
23 [[nodiscard]] std::span<unsigned> used() { return used_storage; }
24};
25
26template <class T>
27decltype(auto) set_params(T &t, std::string_view prefix, Options &opts) {
28 return alpaqa::params::set_params(t, prefix, opts.options(), opts.used());
29}
std::span< unsigned > used()
Definition options.hpp:23
std::span< const std::string_view > options() const
Definition options.hpp:20
std::vector< std::string_view > options_storage
Definition options.hpp:12
std::vector< unsigned > used_storage
Definition options.hpp:13
Options(int argc, const char *const argv[])
Definition options.hpp:16
void set_params(T &t, std::string_view prefix, std::span< const std::string_view > options, std::optional< std::span< unsigned > > 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:27