Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Class templates and inlining (OT)

Author: Dave Gomboc

Date: 03:01:05 12/24/02

Go up one level in this thread


On December 24, 2002 at 05:51:29, Sune Fischer wrote:

>On December 24, 2002 at 05:48:43, Dave Gomboc wrote:
>
>>C++ has built-in templates for most of those.  Look up max, min, and swap in
>>your (up-to-date!) C++ documentation.  They're all in the standard ("std")
>>namespace.
>>
>>Dave
>
>Do you know if they will be inlined, ie. are they as fast as macros?
>
>-S.

A modern C++ compiler would be brain-dead to not inline min, max, and swap for
built-in value types.  So if you're swapping ints, yes.  If you're swapping
MyGargantuanClass, maybe not.

To test, you could create your own namespace (don't use a class!) and write your
own max, min, and swap (which you've already done :-) inside of it.

e.g.

namespace util = Sune_Convenience_Function {

    // declare max here
    // declare min here
    // declare swap here
};

// later on...

   util::swap(a, b);

of course, std::swap will give you C++'s built-in swap.


Regarding inlining, you can ask a C++ compiler to inline with the "inline"
keyword, but it isn't mandatory that it does so, it's just a hint.  Elsewhere in
this thread you indicated that you are using MSVC 6.  MSVC supports
"__forceinline" also, which lets you insist that the compiler inline it.  Be
warned that MSVC 6 is extremely obsolete.  Microsoft (actually, they are not
alone in this) doesn't have a conforming C++ compiler out yet, but Visual C++ 7
with Service Pack 1 will be significantly less behind-the-curve.

Dave



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.