Are templates, namespaces and std:: worth using?

Started by
16 comments, last by neurokaotix 21 years, 1 month ago
Additionally, techniques such as expression templates may improve your code''s performace.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Do expression templates require something like a meta copiler? If yes, then they are bad. Instead, I recommend the boost libraries. They are really great. It''s worth to take a look.
quote:Original post by Anonymous Poster
Do expression templates require something like a meta copiler?

Why don''t you try reading the article?
quote:
If yes, then they are bad.

How so?
No meta compiler required, just a highly conformant C++ compiler.

C++ templates definatly do not slow things down. In fact, I can''t think of a way that they can slow things down, because they work at compile time only. Generic Programming, Compile Time Polymorphism, that kind of stuff.

let''s take an example:

Say I have a program that needs to calculate..say...n factorial a whole lot of times in my program. Doing this in run time is expensive, but say for instance I know these numbers at compile time, n.

I can write a template to do it for me.



template < unsigned int n>
class Factorial {

enum { value = Factorial< n-1 >::value*n };

};

template < >
class Factorial< 0 > {
enum { value = 1 };
};



Could also use a static const int64 or something so you don''t overflow the enum, but that''s implementation.


Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
The worst thing about templates is that Microsoft can''t get their act together to provide good support for them
no, the worst thing is that people persist in using microsoft compilers.
Visual Studio.NET 2K3 supports them as well as any other compiler I''ve seen. VC6 is the worst, but that came our before the standard was finalized.


Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
quote:Original post by CpMan
VC6 is the worst, but that came our before the standard was finalized.


I''m pretty sure Visual C++ 6 was released after the standard was finalized, but only by a month or two, so the compiler code were probably pretty much done when the standard was approved. While that would make it unreasonable to expect 100% standard conformance, the support could certainly have been vastly better if they had put any effort into it, with Microsoft involved in the standardization process and all...

This topic is closed to new replies.

Advertisement