
19-02-2014, 22:31
|
 |
Registered User
AKA: Eric
 FRC #1425 (Error Code Xero)
Team Role: Mentor
|
|
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
|
|
|
Re: Function-in-a-line!!! (C/C++)
Quote:
Originally Posted by yash101
Since I have started vision processing, these are nifty functions, that I've consicified into a single line so they are out of the way of your real code!
Code:
//string funcs, requiring string and sstream
string bool2str(bool in) { stringstream str; str << in; return str.str(); }
string int2str(int inp) { stringstream str; str << inp; return str.str(); }
string double2str(double in) { stringstream str; str << in; return str.str(); }
//math functions!
double tanDeg(double input) { return tan((input) * pi / 180); }
double hypotenuse(double legA, double legB) { return sqrt(((legA*legA) + (legB*legB))); }
double leg(double hypotenuse, double leg) { return sqrt(((hypotenuse*hypotenuse) - (leg*leg))); }
Give me any feedback and post more of these single-liner c functions!
|
Use a template:
Code:
template<typename T>
string as_string(T const& t){
stringstream ss;
ss<<t;
return ss.str();
}
|