codac 1.5.6
Loading...
Searching...
No Matches
codac2_template_tools.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <memory>
13#include "codac2_Matrix.h"
14#include "codac2_Vector.h"
15
16namespace codac2
17{
18 template<class T>
19 concept IsRealType = (std::is_same_v<double,T>
20 || std::is_same_v<Vector,T>
21 || std::is_same_v<Matrix,T>);
22
23 inline Index size_of([[maybe_unused]] int x)
24 {
25 return 1;
26 }
27
28 inline Index size_of([[maybe_unused]] double x)
29 {
30 return 1;
31 }
32
33 template<typename T>
34 inline Index size_of(const T& x)
35 {
36 return x.size();
37 }
38
39 template<typename T1, typename T2>
40 inline bool same_size(const T1& x1, const T2& x2)
41 {
42 return size_of(x1) == size_of(x2);
43 }
44
45 template<class... T>
46 bool all_same_size(const T&... x)
47 {
48 return (... && (same_size(std::get<0>(std::make_tuple(x...)), x)));
49 }
50
51 template<class... T>
52 Index size_first_item(const T&... x)
53 {
54 return size_of(std::get<0>(std::make_tuple(x...)));
55 }
56
57 // Removes duplicates when no comparison operator is available
58 template<typename T>
59 void remove_duplicates_from_list(std::list<T>& l)
60 {
61 typename std::list<T>::iterator it = l.begin();
62 while(it != l.end())
63 {
64 if(std::count(l.begin(), l.end(), *it) > 1)
65 l.erase(it++);
66 else
67 ++it;
68 }
69 }
70
71 template<typename C>
72 requires is_ctc_v<C>
73 inline Index size_of(const std::shared_ptr<C>& x)
74 {
75 return x->size();
76 }
77
78 template<typename S>
79 requires is_sep_v<S>
80 inline Index size_of(const std::shared_ptr<S>& x)
81 {
82 return x->size();
83 }
84
85 template<int R,int C>
86 inline auto vectorVector_to_vectorIntervalVector(const std::vector<Mat<double,R,C>>& x)
87 {
88 std::vector<Mat<Interval,R,C>> v(x.size());
89 for(size_t i = 0 ; i < x.size() ; i++)
90 v[i] = x[i].template cast<Interval>();
91 return v;
92 }
93}