When do you use templates instead of CTFE?

Jonathan M Davis jmdavisProg at gmx.com
Sun Mar 25 16:35:36 PDT 2012


On Sunday, March 25, 2012 17:55:56 Nick Sabalausky wrote:
> "Timon Gehr" <timon.gehr at gmx.ch> wrote in message
> news:jkkbqv$2pvu$3 at digitalmars.com...
> 
> > On 03/24/2012 07:42 AM, Dan wrote:
> >> Since there is CTFE, I keep running into, do I really need this as a
> >> template parameter? Why not put this in a constructor. And so on...
> > 
> > You use templates in combination with CTFE if
> > 
> > - You have to perform computations on types.
> > - You want template instantiation syntax.
> > 
> >   (If this is the only reason, the template will just wrap a CTFE
> > 
> > computation)
> 
> Yea, the general rule of thumb is "If you can do it with CTFE, then do so,
> otherwise use templates."

Generally, you end up having to use templates for stuff that operates on 
types, whereas CTFE works for stuff that can be normal functions.

- Jonathan M Davis


More information about the Digitalmars-d mailing list