raberu v1.1.0
Fancy Named Parameter Library
 
Loading...
Searching...
No Matches

◆ merge()

template<concepts::option... K1s, concepts::option... K2s>
constexpr auto merge ( settings< K1s... > const &  opts,
settings< K2s... > const &  defs 
)
related

Merge two instances of rbr::settings.

Merge all options of opts and defs. If an options is present in both arguments, the one from opts is used.

Parameters
optsrbr::settings to merge
defsrbr::settings acting as default value
Returns
An instance of rbr::settings containing all options from opts and any options from defs not present in opts.

Example:

#include <raberu/raberu.hpp>
#include <iostream>
int main()
{
using namespace rbr::literals;
constexpr auto modal = "modal"_fl;
constexpr auto similar = "similar"_fl;
auto defaults = rbr::settings("name"_kw = std::string{"Jane Doe"}, "value"_kw = 42.69f, modal);
auto opts = rbr::settings("value"_kw = 956.7f, similar);
auto merged = rbr::merge(opts, defaults);
std::cout << merged[modal] << "\n";
std::cout << merged["name"_kw] << "\n";
std::cout << merged[similar] << "\n";
std::cout << merged["value"_kw] << "\n";
}
Raberu literals namespace.
Definition: keywords.hpp:369
Defines a group of options for processing.
Definition: settings.hpp:50