#include #include #include #include #include #include #include using namespace std; template class PNorm{ private: using X = typename Vec::value_type; public: X operator()(const Vec& v) { X x = 0; for (const X& y: v) x += pow(y, p); return pow(x, static_cast(1) / p); } }; template class PNorm{ private: using X = typename Vec::value_type; public: X operator()(const Vec& v) { X x = 0; for (const X& y: v) x += y * y; return sqrt(x); } }; int main() { vector c{5, 6}; array a{3, 4}; cout << setprecision(numeric_limits::digits10 + 1) << PNorm>{}(c) << endl << PNorm, 3>{}(a) << endl; }