Horizon
range_util.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "canvas/selectables.hpp"
4 #include <range/v3/view.hpp>
5 #include <range/v3/algorithm.hpp>
6 
7 namespace horizon {
8 inline auto sel_filter_type(ObjectType type)
9 {
10  return ranges::views::filter([type](const SelectableRef &x) { return x.type == type; });
11 }
12 
13 template <typename Tk, typename Tv> auto map_ptr_from_sel(std::map<Tk, Tv> &m)
14 {
15  return [&m](const SelectableRef &x) { return &m.at(x.uuid); };
16 }
17 
18 
19 template <typename Tk, typename Tv> auto map_ref_from_sel(std::map<Tk, Tv> &m)
20 {
21  return ranges::views::transform([&m](const SelectableRef &x) -> Tv & { return m.at(x.uuid); });
22 }
23 
24 template <typename Tr, typename Tp> auto find_if_ptr(Tr &&range, Tp pred)
25 {
26  auto x = ranges::find_if(range, pred);
27  if (x == range.end())
28  return static_cast<decltype(&*x)>(nullptr);
29  else
30  return &*x;
31 }
32 } // namespace horizon
CPP_concept type
\concept type
Definition: concepts.hpp:838
CPP_concept range
\concept range
Definition: concepts.hpp:69
_t< detail::find_if_< L, Fn > > find_if
Return the tail of the list L starting at the first element A such that invoke<Fn,...
Definition: meta.hpp:2506
_t< detail::transform_< list< Args... > >> transform
Return a new meta::list constructed by transforming all the elements in L with the unary invocable Fn...
Definition: meta.hpp:1855
join< transform< L, detail::filter_< Pred > >> filter
Returns a new meta::list where only those elements of L that satisfy the Callable Pred such that invo...
Definition: meta.hpp:2818