23#ifdef __cpp_lib_execution
28 template<sp_i IT, std::invocable<IT> F>
void for_each(
const IT start,
const IT
end, F&& FN) {
30 static tbb::affinity_partitioner ap;
31 tbb::parallel_for(start,
end, std::forward<F>(FN), ap);
33 for(IT I = start; I <
end; ++I) FN(I);
37 template<sp_i IT, std::invocable<IT> F>
void for_each(
const IT
end, F&& FN) {
return for_each(
static_cast<IT
>(0),
end, std::forward<F>(FN)); }
40#ifdef __cpp_lib_execution
41 return std::max_element(std::execution::par, start,
end);
43 return std::max_element(start,
end);
47 template<
typename T> [[maybe_unused]]
const std::vector<T>&
unique(std::vector<T>& container) {
48 std::sort(container.begin(), container.end());
49 container.erase(std::unique(container.begin(), container.end()), container.end());
50 container.shrink_to_fit();
54 template<
typename T>
constexpr T&
hacker(
const T& I) {
return const_cast<T&
>(I); }
56 template<
typename T>
constexpr T*&
hacker(
const T*
const& I) {
return const_cast<T*&
>(I); }
58 template<
typename T>
T sign(
const T& I) {
return (I >
T(0)) - (I <
T(0)); }
60 template<
typename T>
bool approx_equal(
T x,
T y,
int ulp = 2)
requires (!std::numeric_limits<T>::is_integer) {
return fabs(x - y) <= std::numeric_limits<T>::epsilon() * fabs(x + y) * ulp || fabs(x - y) < std::numeric_limits<T>::min(); }
62 unsigned long long binomial(
unsigned long long,
unsigned long long);
74 namespace expression {
75 std::vector<std::pair<string, unsigned>>
split(std::string_view variable_string);
79template<
typename T>
bool get_input(istringstream& I,
T& O) {
return static_cast<bool>(I >> O); }
81template<
typename T>
bool get_input(istringstream& I, Col<T>& O) {
83 for(
auto&
P : O) code &=
static_cast<bool>(I >>
P);
87template<
typename T>
bool get_input(istringstream& I, std::vector<T>& O) {
89 while(
get_input(I, value)) O.emplace_back(value);
93template<
typename T,
typename...
U>
bool get_input(istringstream& I,
T& O,
U&... R) {
return static_cast<bool>(I >> O) ?
get_input(I, R...) :
false; }
104 if(I.eof())
return true;
106 return static_cast<bool>(I >> O);
111 for(
auto&
P : O) code &= I.eof() ? true :
static_cast<bool>(I >>
P);
116 if(I.eof())
return true;
123bool is_equal(
const char*,
const char*);
126bool is_equal(
const string&,
const char*);
127bool is_equal(
const char*,
const string&);
128bool is_equal(
const string&,
const string&);
129bool is_equal(std::string_view,
const char*);
130bool is_equal(
const char*, std::string_view);
136template<std::equality_comparable T> std::pair<bool, std::int64_t>
if_contain(
const std::vector<T>& container,
const T target) {
137 auto position = std::find(container.begin(), container.end(), target);
139 return {position != container.end() && container.size() > 0, position - container.begin()};
149double perturb(
double,
double = 1
E-5);
Storage< T >::iterator end(Storage< T > &S)
Definition Storage.hpp:202
std::vector< std::pair< string, unsigned > > split(std::string_view variable_string)
Definition utility.cpp:69
Definition MatrixModifier.hpp:36
const std::vector< T > & unique(std::vector< T > &container)
Definition utility.h:47
char to_lower(char)
Definition utility.cpp:37
T sign(const T &I)
Definition utility.h:58
unsigned long long binomial(unsigned long long, unsigned long long)
Definition utility.cpp:21
char to_upper(char)
Definition utility.cpp:35
constexpr T max_element(T start, T end)
Definition utility.h:39
bool approx_equal(T x, T y, int ulp=2)
Definition utility.h:60
void for_each(const IT start, const IT end, F &&FN)
Definition utility.h:28
constexpr T & hacker(const T &I)
Definition utility.h:54
bool get_input(istringstream &I, T &O)
Definition utility.h:79
bool is_integer(const string &)
Definition utility.cpp:133
bool is_false(const char *)
Definition utility.cpp:127
string get_remaining(istringstream &)
Definition utility.cpp:98
void ignore_whitespace(istringstream &)
Definition utility.cpp:92
bool if_contain(const string &, const char *)
Definition utility.cpp:119
double perturb(double, double=1E-5)
Definition utility.cpp:135
bool is_equal(const char *, const char *)
Definition utility.cpp:103
bool get_optional_input(istringstream &I, T &O)
Definition utility.h:103
bool is_true(const char *)
Definition utility.cpp:125