www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D vs C++ metaprogramming: why are c++ templates inherently slow

reply evansl <cppljevans suddenlink.net> writes:
This post is in response to Nick's suggestion in this post:


http://forum.dlang.org/thread/k524ke$gvt$1 digitalmars.com#post-20121104000747.00001f10:40unknown

to repost the question here. (please note I have read the
link Nick provided, but as noted in my last post to the c++
list, that link, although very convincing, did not answer
my question about why ADL and partial specialization are
one of the causes of slow compile times.)

So here's the original post to the c++ newsgroup:

In this post:

  http://article.gmane.org/gmane.comp.lib.boost.devel/189925

Eric indicates that Walter Bright believes, in c++:

  that instantiating a template is inherently expensive, and certain
  features of the C++ language (ADL, partial specialization, etc.)
  force that to be the case.

Walter, if Eric is remembering correctly, could you provide a little
more explanation on why this is so or provide a link to some document
supporting this conclusion?

TIA.

-regards,
Larry
Nov 04 2012
parent reply "Mehrdad" <wfunction hotmail.com> writes:
On Sunday, 4 November 2012 at 16:44:30 UTC, evansl wrote:
   that instantiating a template is inherently expensive

Just a guess, but perhaps pattern-matching templates is NP-complete?
Nov 04 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 11/04/2012 08:47 PM, Mehrdad wrote:
 On Sunday, 4 November 2012 at 16:44:30 UTC, evansl wrote:
   that instantiating a template is inherently expensive

Just a guess, but perhaps pattern-matching templates is NP-complete?

That does not say anything about evaluation speed.
Nov 04 2012