I want to create debug template for array for printing array. This is my template
#define debug(x) cerr << #x <<" = "; print(x); cerr << endl;
void print(ll t) {cerr << t;}
void print(int t) {cerr << t;}
void print(float t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(T arr[]) {cerr << "[ "; for (T i : arr) {print(i); cerr << " ";} cerr << "]";}
But its giving some errors for array but vector works fine,
template <class T> void print(T arr[]) {cerr << "[ "; for (T i : arr) {print(i); cerr << " ";} cerr << "]";}
^~~
A.cpp:16:55: note: suggested alternatives:
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits\stdc++.h:95:0,
from A.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\valarray:1206:5: note: 'std::begin'
begin(const valarray<_Tp>& __va)
^~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\valarray:1206:5: note: 'std::begin'
A.cpp:16:55: error: 'end' was not declared in this scope
template <class T> void print(T arr[]) {cerr << "[ "; for (T i : arr) {print(i); cerr << " ";} cerr << "]";}
^~~
A.cpp:16:55: note: suggested alternatives:
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits\stdc++.h:95:0,
from A.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\valarray:1226:5: note: 'std::end'
end(const valarray<_Tp>& __va)
^~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\valarray:1226:5: note: 'std::end'
So how to create a debug for array ?