Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > A use-case for ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 9300 of 10096
Post > Topic >>

A use-case for recursive constexpr

by Joe Gottman <jgottman@[EMAIL PROTECTED] > Feb 19, 2008 at 10:06 PM

This post should really go to comp.std.c++, but since it's down
I'm posting it here instead.  The new constexpr keyword from C++0x does
not allow recursive constexpr functions, because the designers could not
think of a good use case.  I've just thought of one: a compile time
greatest common factor function.  It could be defined recursively as:

template <class X>
inline constexpr X gcf(X a, X b)
{
    return (b == 0) ? abs(a) : gcf(b, a % b);
}

This would be useful in the implementation of duration class template
proposed in N2498
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2498.html).
This class template has the form

	template <class TickType,
	long long TicksPerSecond,
	long long SecondsPerTick>
	class duration;

and it sometimes needs to compute a compile-time greatest common factor
between the TicksPerSecond template parameters of two different
instantiations.

Joe Gottman


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 6 Posts in Topic:
A use-case for recursive constexpr
Joe Gottman <jgottman@  2008-02-19 22:06:19 
Re: A use-case for recursive constexpr
Travis Vitek <travis.v  2008-02-19 23:44:34 
Re: A use-case for recursive constexpr
Geert-Jan Giezeman <ge  2008-02-20 07:20:00 
Re: A use-case for recursive constexpr
Joe Gottman <jgottman@  2008-02-20 21:30:01 
Re: A use-case for recursive constexpr
Richard Corden <richar  2008-02-22 08:42:25 
Re: A use-case for recursive constexpr
Alberto Ganesh Barbati &l  2008-02-25 00:06:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:37:05 CDT 2008.