Я не понимаю почему элементы мапы и вектора не возводятся в квадрат. #include
#include
#include
#include
using namespace std;

template
T Sqr(T a) {
a *= a;
return a;
}

template
pair Sqr(pair p) {
return {Sqr(p.first), Sqr(p.second)};
}

template
map Sqr(map m) {
for (pair i : m) {
i.second = Sqr(i.second);
}
return m;
}

template
vector operator*(vector lhs, const vector & rhs) {
for (T i : lhs) {
i = Sqr(i);
}
return lhs;
}

int main() {
// Пример вызова функции
vector v = {1, 2, 3};
cout << "vector:";
for (int x : (v * v)) {
cout << ' ' << x;
}
cout << endl;

map > map_of_pairs = {
{4, {2, 2}},
{7, {4, 3}}
};
cout << "map of pairs:" << endl;
for (const auto& x : Sqr(map_of_pairs)) {
cout << x.first << ' ' << x.second.first << ' ' << x.second.second << endl;
}

int a = 2;
cout << Sqr(a);
}

Зубканай Зубканай    1   19.07.2021 14:56    1

Другие вопросы по теме Информатика