Topic: Can we take the `address' of built-in operations? (For templates)
Author: mat@mole-end
Date: Mon, 22 Jun 1992 02:55:58 GMT Raw View
== Let's say I have a template:
template< class T_1, class T_2, int (*C_fun)( const T_1&, const T_2& ) >
class Comparezem
{
public:
static int comp( T_1 l, T_2 r ) { return (*C_fun)( l, r ); };
}
== Now I want to write
typedef Comparezem< int, int, (&::operator<( int, int )) > I_I_c;
== Is this legal? Can I depend on C++ to create a `function' to
represent ( int < int ) ? SHOULD I be able to depend on C++ to
create sich a function?
== (Never mind the lexical and syntactic mess of trying to write
``operator<( .. )'' inside a template argument list! Do we have to
write something like this:
static int (* const funee)( int, int ) = &::operator<( int, int );
typedef Comparezem< int, int, funee > I_I_c;
??? Or is that even legal? Somehow, I doubt it. And you CAN'T make
funee into an enum ...)
== Yes, I know that this is a mind-bender. But I can imagine a
circumstance in which this might be desired. And if I can imagine it,
I'm sure someone will need it sooner or later. My brief stint in
support of a C compiler convinced me that not only are programmers' uses
of a language stranger than we imagine, those uses are stranger than
we CAN imagine--to steal a good line from someone (Arthur C. Clarke?)
== Let's try a variation. How about if we make the template demand a
member function? :
template< class T_1, class T_2, int (T_1::*C_fun)( const T_2& ) const >
class Comparezem
{
public:
static int comp( T_1 l, T_2 r ) { return (l.*C_fun)( r ); };
}
== In which case I'd write:
typedef Comparezem< int, int, &int::operator<( int ) > I_I_c;
== Could THIS be legal???
My apologies if these have already been considered; I don't recall
reading of them. (An RTFM to the ARM with a page number will do, if
it's available.)
--
(This man's opinions are his own.)
From mole-end Mark Terribile
uunet!mole-end!mat, Somewhere in Matawan, NJ