Skip to main content
Include the name of the author of the linked article as required in https://stackoverflow.com/help/referencing
Source Link
dbc
  • 120k
  • 27
  • 273
  • 404

I just came across this linkarticle by Danny Kalev which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 

I just came across this link which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 

I just came across this article by Danny Kalev which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 
added 27 characters in body
Source Link
Melchia
  • 24.5k
  • 23
  • 110
  • 130

I just came across http://www.informit.com/articles/article.aspx?p=2209021this link which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 

I just came across http://www.informit.com/articles/article.aspx?p=2209021 which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 

I just came across this link which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float> 
Source Link

I just came across http://www.informit.com/articles/article.aspx?p=2209021 which has a great tip for C++14 and up.

template<typename T> constexpr T pi = T(3.1415926535897932385); 

I thought this was pretty cool (though I would use the highest precision PI in there I could), especially because templates can use it based on type.

template<typename T> T circular_area(T r) { return pi<T> * r * r; } double darea= circular_area(5.5);//uses pi<double> float farea= circular_area(5.5f);//uses pi<float>