CsPaint  1.0.1
cspaint_util.h
1 
19 #ifndef INCLUDED_CSPAINT_UTIL_H
20 #define INCLUDED_CSPAINT_UTIL_H
21 #include <algorithm>
22 #include <functional>
23 #include <type_traits>
24 #include <vector>
25 
26 namespace CsPaint
27 {
28 
29 namespace util
30 {
31 template <typename T>
33 {
34  public:
35  template <typename... Args>
36  static std::shared_ptr<T> create(Args &&... args)
37  {
38  auto ptr = std::make_shared<T>(std::forward<Args>(args)...);
39  ptr->init(ptr);
40  return ptr;
41  }
42 
43  private:
44  friend T;
45  struct private_tag {
46  };
47 };
48 
49 template <typename T, typename Func>
50 // std::vector<decltype(std::declval<Func>()(std::declval<T>()))> map_vector(const std::vector<T>
51 // &input, Func f)
52 std::vector<std::invoke_result_t<Func, T>> map_vector(const std::vector<T> &input, Func f)
53 {
54  std::vector<std::invoke_result_t<Func, T>> newData;
55  newData.reserve(input.size());
56  for (auto &item : input) {
57  newData.push_back(f(item));
58  }
59 
60  return newData;
61 }
62 
63 template <typename T, typename Func>
64 std::vector<T> filter_vector(std::vector<T> input, Func f)
65 {
66  input.erase(std::remove_if(input.begin(), input.end(), [&f](const T &data) { return !f(data); }),
67  input.end());
68  return input;
69 }
70 
71 template <typename T>
72 constexpr bool nomove_nocopy_nodefault()
73 {
74  return !std::is_move_constructible_v<T> && !std::is_copy_constructible_v<T> &&
75  !std::is_move_assignable_v<T> && !std::is_copy_assignable_v<T> &&
76  !std::is_constructible_v<T>;
77 }
78 };
79 };
80 #endif
constexpr bool nomove_nocopy_nodefault()
Definition: cspaint_util.h:72
std::vector< T > filter_vector(std::vector< T > input, Func f)
Definition: cspaint_util.h:64
std::vector< std::invoke_result_t< Func, T > > map_vector(const std::vector< T > &input, Func f)
Definition: cspaint_util.h:52
static std::shared_ptr< T > create(Args &&...args)
Definition: cspaint_util.h:36
Definition: cspaint_util.h:32
Definition: cspaint_buffer.h:26