15template <
class T1 =
void,
class T2 =
void>
17 constexpr T1 operator()(
const std::pair<T1, T2>& pair)
const {
25 template <
class T1,
class T2>
26 constexpr auto operator()(
const std::pair<T1, T2>& pair)
const
27 ->
decltype(
static_cast<const T1&
>(pair.first)) {
28 return static_cast<const T1&
>(pair.first);
33template <
class T1 =
void,
class T2 =
void>
35 constexpr T2 operator()(
const std::pair<T1, T2>& pair)
const {
43 template <
class T1,
class T2>
44 constexpr auto operator()(
const std::pair<T1, T2>& pair)
const
45 ->
decltype(
static_cast<const T2&
>(pair.second)) {
46 return static_cast<const T2&
>(pair.second);
58template<
typename ForwardIt,
typename T>
59T
min_value(ForwardIt first, ForwardIt last, T fallback) {
60 auto it = std::min_element(first, last);
61 return it != last ?
static_cast<T
>(*it) : fallback;
74template<
typename ForwardIt,
typename UnaryOp,
typename T>
75T
min_value(ForwardIt first, ForwardIt last, UnaryOp operation, T fallback) {
76 auto it = std::min_element(first, last, [&operation](
const auto& left,
const auto& right) {
77 return operation(left) < operation(right);
79 return it != last ?
static_cast<T
>(operation(*it)) : fallback;
90template<
typename ForwardIt,
typename T>
91T
max_value(ForwardIt first, ForwardIt last, T fallback) {
92 auto it = std::max_element(first, last);
93 return it != last ?
static_cast<T
>(*it) : fallback;
106template<
typename ForwardIt,
typename UnaryOp,
typename T>
107T
max_value(ForwardIt first, ForwardIt last, UnaryOp operation, T fallback) {
108 auto it = std::max_element(first, last, [&operation](
const auto& left,
const auto& right) {
109 return operation(left) < operation(right);
111 return it != last ?
static_cast<T
>(operation(*it)) : fallback;
124template <
class InputIt,
class UnaryOp>
125std::string
transform_join(
const InputIt first,
const InputIt last, UnaryOp operation,
const std::string& separator,
bool trailing_separator =
false) {
126 std::string res =
"";
128 for(
auto curr = first; curr != last; ++curr) {
129 res += operation(*curr);
130 if(last - curr > 1 || trailing_separator)
147template <
class InputIt>
148std::string
join(
const InputIt first,
const InputIt last,
const std::string& separator,
bool trailing_separator =
false) {
149 return transform_join(first, last, [](
const auto& val) {
return to_string(val); }, separator, trailing_separator);
162template<
class InputIt,
class OutputIt>
163OutputIt
pair_adjacent(
const InputIt first,
const InputIt last, OutputIt d_first) {
164 if(std::distance(first, last) > 1) {
165 return std::transform(first, std::prev(last), std::next(first), d_first, [](
const auto& a,
const auto& b) {
166 return std::make_pair(a, b);
180template<
class InputIt>
181std::vector<std::pair<typename InputIt::value_type, typename InputIt::value_type>>
pair_adjacent(
const InputIt first,
const InputIt last) {
182 std::vector<std::pair<typename InputIt::value_type, typename InputIt::value_type>> res;
std::string join(const InputIt first, const InputIt last, const std::string &separator, bool trailing_separator=false)
Concatenate elements in the range [first, last) to a std::string.
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
std::string transform_join(const InputIt first, const InputIt last, UnaryOp operation, const std::string &separator, bool trailing_separator=false)
Transform elements in the range [first, last) and concatenate them to a std::string.
T min_value(ForwardIt first, ForwardIt last, T fallback)
Find the minimum value in the range [first, last) or return fallback if the range is empty.
OutputIt pair_adjacent(const InputIt first, const InputIt last, OutputIt d_first)
Transform the elements in the range [first, last) to adjacent pairs and store the results in an outpu...
T max_value(ForwardIt first, ForwardIt last, T fallback)
Find the maximum value in the range [first, last) or return fallback if the range is empty.
Return std::pair::second.