[M3devel] scope/resolution of foo in interface foo = foo(bar)

Jay K jay.krell at cornell.edu
Sat Jan 2 20:18:58 CET 2010


> Date: Sat, 2 Jan 2010 11:42:34 -0600
> From: rodney
> On a separate issue, one of the things that the C++ template facility really
> botched badly is that instantiations not only can be, but must be, anonymous.


Can be, but not must be.


for types:
  typedef vector<int> vi_t.


for functions, well, usually the parameters are deduced and you
don't have to say them:


template <typename T> T max(const T& a, const T& b)
{
  return (a > b ? a : b);
}


max(1, 2);


If you have something like:


template <typename T> T* New() { return new T(); }

then you do have to say New<Foo>().
You could do something onerous like:
Foo* (*const NewFoo)() = New<T>;


There is a new feature that might enable:


const auto NewFoo = New<T>;



but really, deduction of function template parameters is a very good thing,
no need to fight it, and making the parameters explicit
for some scenarios is not so bad.


There are some very confusing things about templates:
  How much can be checked without instantiation?
  Which names are bound at template definition vs. instantiation?
  Can "template metaprogramming" be done in a more direct way instead
    of seemingly just being an accident?


And (with reverse spin) there are some very powerful things you can do with templates:
   template meta programming :) 
   very good levels of inlining where otherwise you'd have little choice but to use
     function pointers and have poor efficiency (though, not that you can't 
     implement things easily enough and have them at least work without templates)
   not sure the term, but have you seen how in C++ you can write:
     a = b + c + d + e;


where the types involves are vectors/matrices and it compiles down
to have no temporary vectors/matrices.


 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100102/76746498/attachment-0002.html>


More information about the M3devel mailing list