I really like the template of this code and have seen this many times , so i need to understand this!
specially the trace part and if i want to print vector then will it also help in that as well or not
@aryan_007 hey please send me the code part here which you want to understand and what you want to understand in that part.
@aryan_007 hey thats not way of writing as its very complex and we define function simply and usually that functionform in which it is written is inbuilt functions of C++ thats why they are written in this form. Just focus on simple coding with clean code with norml things like typedef , functions, macros etc.
sir , so what should be used to debug the code faster , if i have any data structure or vector and i need to iterate and check , so i guess that trace is being used !! but how i don’t know that !!
@aryan_007 bro these are high level concepts and not used anywhere in my life till now as for debugging you have to do it manually like using print statements and other things which is done manually dont work about them just focus on problem solving and logic as ye kabhi kam nhi ayenge apke.
sir , writing a print statemnent waste a lot of time , so i use watch , but i use it for at max 3 variables , so their must be a better way to debug things and i think it is one of those ways , that’s why i was asking !!
@aryan_007 actually for logic purpose checking you have to check that with print itself also for debugging in devlopment code you can use debuggers inbuilt to code ide like in webstorm etc
Was this doubt reopened by you? As I see that it has been replied, earlier.
Please state the reason or what is it that you want.
yups , i want to know what that trace , gcc target and pragma comment do in the above code ?? specially trace !!
trace is just a helper function, to debug the variable values.
so can i pass any number of argument or any 1d or 2d vector in it , or it work like something else
you can pass any number of arguments, just that there should be a defined operator for the ouput of that type.
For example, you can use cout with string, int, double …, therefore you can also use trace for these data types.
#include<bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
int main()
{
int n = 10;
double v[n];
for (int i = 0; i < n; ++i) {
trace(i, v[i], i * i);
}
return 0;
}
run this simple example and things will be clear.
Also, note that you shouldn’t blindly copy someone (just because he went to Google or any good place). These things don’t really matter. What matters is your coding skills.
nhi nhi sir , i didn’t even knew he went into google ,i see that many coders debug faster bcz of customised print statements which really help in short contest .
Okay for that, I have sent you the code above, it will make things clearer.
yaa yaaa sir , i got that tarce part , thanks a lot : ) , can you please also help out with the GCC target and pragma comment part !!
GCC target is a kind of compiler optimization, it is best to avoid these, (unless you know what actually is going on), though sometimes they are helpful when your code is slightly above the time limit, where these optimizations can reduce the running time for your code.
#pragma comment linker is a flag for the compiler to increase the stack size, to avoid stack overflow.
