TermOx
pipe_utility.hpp
1 #ifndef TERMOX_WIDGET_DETAIL_PIPE_UTILITY_HPP
2 #define TERMOX_WIDGET_DETAIL_PIPE_UTILITY_HPP
3 #include <memory>
4 #include <type_traits>
5 
6 #include <termox/widget/widget.hpp>
7 
8 namespace ox::pipe::detail {
9 
11 template <typename Predicate>
13  public:
14  explicit Filter_predicate(Predicate p) : predicate{p} {}
15 
16  public:
17  Predicate predicate;
18 };
19 
21 template <typename W>
23  public:
24  using Widget_t = W;
25 };
26 
27 template <typename T>
28 struct is_widget_ptr : std::false_type {};
29 
30 template <typename X>
31 struct is_widget_ptr<std::unique_ptr<X>> : std::is_base_of<ox::Widget, X> {};
32 
34 template <typename T>
35 constexpr bool is_widget_ptr_v = is_widget_ptr<T>::value;
36 
38 template <typename T>
39 constexpr bool is_widget_v = std::is_base_of_v<Widget, std::decay_t<T>>;
40 
42 template <typename T>
43 constexpr bool is_widget_or_wptr =
44  is_widget_v<T> || is_widget_ptr_v<std::decay_t<T>>;
45 
46 } // namespace ox::pipe::detail
47 
48 namespace ox {
49 
51 template <typename T>
52 [[nodiscard]] constexpr auto get(T& x) -> auto&
53 {
54  if constexpr (::ox::pipe::detail::is_widget_ptr_v<T>)
55  return *x;
56  else
57  return x;
58 }
59 
60 } // namespace ox
61 #endif // TERMOX_WIDGET_DETAIL_PIPE_UTILITY_HPP
Used to call operator| overload to create a new Range from filter predicate.
Definition: pipe_utility.hpp:22
Used to call operator| overload to create a new Range from filter predicate.
Definition: pipe_utility.hpp:12
Definition: pipe_utility.hpp:28