9#include <unordered_map>
10#include <unordered_set>
27template <
typename Type1,
typename Type2>
29 const std::pair<Type1, Type2>& pair) {
30 return os <<
"{" << pair.first <<
"; " << pair.second <<
"}";
43template <std::size_t I = 0,
typename... Ts>
44static std::ostream&
PrintTuple(std::ostream& os,
const std::tuple<Ts...>& t) {
45 if constexpr (I <
sizeof...(Ts)) {
46 if (I != 0) os <<
"; ";
63template <
typename... Ts>
64std::ostream&
operator<<(std::ostream& os,
const std::tuple<Ts...>& t) {
79template <
typename Type>
81 const std::vector<Type>& vec) {
84 for (std::size_t i = 0; i < vec.size(); i++) {
86 if (i != vec.size() - 1) os <<
"; ";
102template <
typename K,
typename V>
104 const std::unordered_map<K, V>& map) {
108 for (
const auto& [key, value] : map) {
109 if (!first) os <<
"; ";
111 os << key <<
": " << value;
126 std::string origin = std::to_string(number);
129 origin.erase(origin.find_last_not_of(
'0') + 1, std::string::npos);
132 if (origin.back() ==
'.') origin.pop_back();
148template <
typename Type>
149inline std::istream&
operator>>(std::istream& is, std::vector<Type>& vec) {
153 std::cout <<
"Enter array size: ";
157 std::cerr <<
"Invalid size input." << std::endl;
161 if (size <= 0) std::cout <<
"Invalid size input. Try again: ";
168 std::cout <<
"Enter array elements: ";
169 for (std::size_t i = 0; i < std::size_t(size); i++) {
172 std::cerr <<
"Invalid array input. The entry is incorrect." << std::endl;
193inline bool Contains(
const std::vector<T>& vec,
const T& value) {
194 return std::find(vec.begin(), vec.end(), value) != vec.end();
207 const std::string& substring) {
208 return origin.rfind(substring, 0) == 0 ? origin.erase(0, substring.length())
static std::ostream & PrintTuple(std::ostream &os, const std::tuple< Ts... > &t)
Выводит все элементы std::tuple в поток.
Definition utils.hpp:44
std::ostream & operator<<(std::ostream &os, const std::pair< Type1, Type2 > &pair)
Выводит все элементы пары в поток.
Definition utils.hpp:28
bool Contains(const std::vector< T > &vec, const T &value)
Проверяет наличие элемента в векторе.
Definition utils.hpp:193
std::string ReplacedString(std::string origin, const std::string &substring)
Удаляет подстроку из начала строки, если она там присутствует.
Definition utils.hpp:206
std::string ErasedZerosStr(float number)
Функция, которая обрезает незнач. нули float при преобр. в строку.
Definition utils.hpp:125
std::istream & operator>>(std::istream &is, std::vector< Type > &vec)
Перегрузка, которая вводит все элементы вектора из потока. (работает исключительно с консолью,...
Definition utils.hpp:149