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

◆ operator[]()

template<concepts::option... Opts>
template<concepts::keyword Key>
constexpr auto rbr::settings< Opts >::operator[] ( Key const &  k) const
inlineconstexprnoexcept

Retrieved a value via a keyword.

Retrieve the value bound to a given keyword k inside current rbr::settings instance. If such a keyword is not present, either an instance of rbr::unknown_key is returned or a default value or function call will be returned.

Parameters
kKeywords to check
Returns
If any, the value bound to k.

Example:

#include <raberu/raberu.hpp>
#include <iostream>
int main()
{
using namespace rbr::literals;
int i = 77;
auto values = rbr::settings("size"_kw = 75ULL, "transparent"_fl);
std::cout << values["size"_kw] << "\n";
std::cout << values["transparent"_fl] << "\n";
std::cout << values["value"_kw | 13.37] << "\n";
std::cout << values["modal"_fl | rbr::call([&]() { return i++; })] << "\n\n";
std::cout << "i = " << i << "\n";
}
constexpr auto values(rbr::settings< Opts... > const &s)
Retrieved the list of all value stored in a settings.
Definition: keys_values.hpp:91
Raberu literals namespace.
Definition: keywords.hpp:369
Callable object wrapper for functional default value.
Definition: keywords.hpp:31
Defines a group of options for processing.
Definition: settings.hpp:50