|
Boost : |
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-01-08 08:42:58
Hi boosters,
just want to show you something I discovered
(maybe you already know) which allows template functions to be specialized
for a class without including its header; it does require that classes are
changed internally,
but I assume it will make compilation mucho faster. (another problem is that
I can only
compile it with Comeau, neither GCC 3.2 or vc7 can eat it).
Anyway, the example is quite straightforward:
#include <iostream>
using namespace std;
template< typename C >
void foo( const C& c )
{
foo_impl( c, C::tag() );
}
template< typename C, typename Tag >
void foo_impl( const C& c, Tag t )
{
cout << "default version" << endl;
}
template< typename C >
void foo_impl( const C& c, typename C::bar_tag )
{
cout << "bar specialised version" << endl;
}
class X
{
public:
class tag {};
typedef tag X_tag;
};
class bar
{
public:
class tag {};
typedef tag bar_tag;
};
int main()
{
X x;
bar b;
foo( x );
foo( b );
return 0;
}
Maybe somebody can use it to something in the future?
regards
Thorsten Ottosen, Aalborg University
nesotto_at_[hidden]
---------------------------------------------------
C++:
my_map[key]++;
Java:
if ( !my_map.containsKey( key ) )
my_map.put( key, new Integer( 1 ) );
else
{
Integer count = ( Integer )my_map.get( key ) );
int icount = count.IntValue();
my_map.put( key, new Integer( ++icount ) );
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk