Topic: Templates and nonstandard extensions


Author: Rafal Florek <raf@regionet.regionet.pl>
Date: 1999/12/21
Raw View

Hello

I was testing the templates against some nonstandard extensions, for
instance:

void __fastcall f(int x) { sum+= x; }

class A
{
public:
 void __fastcall f(int x) { sum+= x; }
};

int main()
{
 int t[5]={0,1,2,3,4};
 std::for_each(t, t+5, f);  // *
 A a;
 std::for_each(t, t+5, std::bind1st(std::mem_fun1(A::f), &a)); // **
 return 0;
}


The (*) call compiles and works ok. (passes arguments via processor
registers - intel platform). As the "for_each" function looks like this:

template <class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f) {
  for ( ; first != last; ++first)
    f(*first);
  return f;
}

it means that the "Function" template parameter keeps "__fastcall"

The (**) call doesn't compile. The "mem_fun1" splits its argument into
return value type (R), class (C) and argument type (A) and it looks like it
loses here the "__fastcall" attribute.

I suppose the Standard says nothing about that but it would be nice if both
versions compiled. IMO the "__fastcall" attribute can't be attached neither
to R,C nor to A template parameter, but the expression R (C::*f)(A) could
again include "__fastcall" as it is with version (*)

I tested that example on gnu c++ 2.92.2, MS VC++ 6.0 and Borland Builder
3.0. All of them behaved similarly. Actually gnu compiled both versions but
produced wrong results for the second.

                               Thanks
                               Rafal


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]