Can someone explain this read template ?? I saw it used by many coders.....

Revision en2, by Coder_Shubham_24, 2020-12-31 21:02:40

I didn't get logic for these to lines

  1. f |= (ch == '-')
  2. x = (x << 1) + (x << 3) + (ch ^ 48);
template<class T>void read(T& x)
{
	x = 0; int f = 0; char ch = getchar();
	while (ch < '0' || ch>'9') { f |= (ch == '-'); ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	x = f ? -x : x;
	return;
}
Tags read, #c++ template

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Coder_Shubham_24 2020-12-31 21:02:40 3
en1 English Coder_Shubham_24 2020-12-31 10:17:37 464 Initial revision (published)