GCC Code Coverage Report


Directory: include/raberu/impl/
File: include/raberu/impl/algo/fetch.hpp
Date: 2026-11-21 10:39:38
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 15 15 100.0%
Branches: 1 1 100.0%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 RABERU - Fancy Parameters Library
4 Copyright : RABERU Project Contributors
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 namespace rbr
11 {
12 //====================================================================================================================
13 //! @ingroup stng
14 //! @brief Retrieved a value via a keyword
15 //!
16 //! Retrieve the value bound to a given keyword `k` inside a variadic list of rbr::options.
17 //! If such a keyword is not present, either an instance of rbr::unknown_key is returned or
18 //! a default value or function call will be returned.
19 //!
20 //! @param k Keywords to check
21 //! @param os Options to inspect
22 //! @return If any, the value bound to `k`.
23 //!
24 //! ## Helper Types
25 //! @code
26 //! namespace rbr::result
27 //! {
28 //! template<auto Keyword, typename... Sources> struct fetch
29 //!
30 //! template<auto Keyword, typename... Sources>
31 //! using fetch_t = typename fetch<Keyword,Sources...>::type;
32 //! }
33 //! @endcode
34 //!
35 //! Return the type of a call to rbr::fetch.
36 //!
37 //! ## Example:
38 //! @include doc/fetch.cpp
39 //====================================================================================================================
40 17 template<concepts::keyword K, concepts::option... Os> constexpr decltype(auto) fetch(K const& k, Os const&... os)
41 {
42 17 auto const opts = settings(os...);
43 17 return opts[k];
44 10 }
45
46 //! @overload
47 template<concepts::keyword K, typename V, concepts::option... Os>
48 6 constexpr decltype(auto) fetch(_::type_or_<K, V> const& k, Os const&... os)
49 {
50 6 auto const opts = settings(os...);
51
1/1
✓ Branch 1 taken 1 times.
8 return opts[k];
52 2 }
53
54 //! @overload
55 9 template<typename K, concepts::settings Settings> constexpr decltype(auto) fetch(K const& k, Settings const& opts)
56 {
57 9 return opts[k];
58 }
59
60 namespace result
61 {
62 template<auto Keyword, typename... Sources> struct fetch;
63
64 template<auto Keyword, concepts::option... Os> struct fetch<Keyword, Os...>
65 {
66 using type = decltype(rbr::fetch(Keyword, std::declval<Os>()...));
67 };
68
69 template<auto Keyword, concepts::settings Settings> struct fetch<Keyword, Settings>
70 {
71 using type = decltype(rbr::fetch(Keyword, std::declval<Settings>()));
72 };
73
74 template<auto Keyword, typename... Sources> using fetch_t = typename fetch<Keyword, Sources...>::type;
75 }
76 }
77