Reply to comment

bloat due to templates

While what you've said is correct, there's another factor involved. People who know and love templates tend to avoid old C-style generic programming, such as used in the qsort() routine commonly found on UNIX systems. Such old code worked on arbitrary arguments by taking arguments from the caller specifying void*s to values, sizes in bytes if necessary, and function pointers to operate meaningfully on the memory content. It was not type safe, but it did mean the one block of compiled code could be reused on arbitrary types. Compared to this, instantiating templates for myriad types does generate a lot of executable code. On the other hand, that code might run faster as inlining and other optimisations are possible. Similarly, doing things like "template " where A and B might be the sizeof a couple strings being passed to the constructor can very quickly lead to hundreds of copies of the template as A and B vary. Often, any optimisations that allows aren't worth the bloat. Sometimes, clever programmers will actually use a lightweight template to provide type safety, for example: template class X { typedef map Map; } where E is expected to be an enum, but it's not too painful to convert the values to ints for private Maps.... Cheers, Tony

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.