qxLib
coalesce.h
Go to the documentation of this file.
1 /**
2 
3  @file coalesce.h
4  @author Khrapov
5  @date 10.06.2025
6  @copyright © Nick Khrapov, 2025. All right reserved.
7 
8 **/
9 #pragma once
10 
11 #include <qx/algo/predicates.h>
12 #include <qx/meta/type_traits.h>
13 
14 #include <optional>
15 #include <type_traits>
16 
17 namespace qx
18 {
19 
20 /**
21  @brief Coalesce function, C# `a ?? b` analogue
22  @details Different types version. The result will be cast to return_t.
23  @tparam return_t - type to cast the result to
24  @tparam args_t - parameters types, can be different
25  @param args - template parameter pack
26  @retval - the first valid object or the last one
27 **/
28 template<class return_t, class... args_t>
29 constexpr return_t coalesce(args_t&&... args);
30 
31 /**
32  @brief Coalesce function, C# `a ?? b` analogue
33  @tparam args_t - parameters types, must be the same
34  @param args - template parameter pack
35  @retval - the first valid object or the last one
36 **/
37 template<class... args_t>
38  requires(same_variadic_args_v<args_t...>)
39 constexpr auto coalesce(args_t&&... args);
40 
41 } // namespace qx
42 
43 #include <qx/coalesce.inl>
constexpr return_t coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:31
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:57