__PRETTY_FUNCTION__, functions and templates
Alex Vinokur
alexander.vinokur@telrad.co.il
Tue Jan 4 05:55:00 GMT 2000
In article < 84pus001rnr@enews2.newsguy.com >,
"Johnny Favorite (it means \"Writhing Tentacle of Death\")"
<allen@snakebite.com> wrote:
> Alex Vinokur wrote:
> > 3. __PRETTY_FUNCTION__
> > --FUNCTION__
>
> Since your other two examples were pretty cool-sounding I have to ask
about
> this one. What the heck does __PRETTY_FUNCTION__ do?
>
>
Here is an example.
Alex
//#########################################################
//------------------- C++ code : BEGIN -------------------
#include <iostream>
#include <string>
//==========================================
//------------------------------------------
void foo1 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//------------------------------------------
int foo2 (const string& s1_1, char c1_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return 0;
}
//------------------------------------------
template <typename S1, typename S2, typename S3>
void foo3 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
}
//------------------------------------------
template <typename S1, typename S2, typename S3>
void foo4 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//------------------------------------------
template <typename S0, typename S1, typename S2, typename S3>
S0 foo5 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return S0 ();
}
//==========================================
class AAA
{
public :
//--------------------------
void fooAAA1_1 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
void fooAAA1_2 () const
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
static void fooAAA1_3 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
int fooAAA2 (const string& s1_1, char c1_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return 0;
}
//--------------------------
template <typename S1, typename S2, typename S3>
void fooAAA3 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
template <typename S1, typename S2, typename S3>
void fooAAA4 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
template <typename S0, typename S1, typename S2,
typename S3>
S0 fooAAA5 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return S0 ();
}
};
//==========================================
template <typename T1, typename T2>
class BBB
{
public :
//--------------------------
void fooBBB1_1 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
void fooBBB1_2 () const
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
static void fooBBB1_3 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
int fooBBB2 (const string& s1_1, char c1_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return 0;
}
//--------------------------
template <typename S1, typename S2, typename S3>
void fooBBB3 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
template <typename S1, typename S2, typename S3>
void fooBBB4 ()
{
cout << __PRETTY_FUNCTION__ << endl;
}
//--------------------------
template <typename S0, typename S1, typename S2,
typename S3>
S0 fooBBB5 (const S1& a1_i, S2& a2_i, S3 a3_i)
{
cout << __PRETTY_FUNCTION__ << endl;
return S0 ();
}
};
//==========================================
class XXX {};
class YYY {};
class ZZZ {};
//==========================================
int main ()
{
char char_value = 'Z';
int int_value = 123;
string string_value = "ABCDE";
XXX XXX_value;
YYY YYY_value;
//===============================
cout << endl;
foo1 ();
foo2 (string_value, char_value);
foo3 (string_value, char_value, XXX_value);
foo3 (YYY_value, char_value, XXX_value);
foo4<YYY, int, string> ();
foo4<YYY, XXX, YYY> ();
foo5<int> (string_value, char_value, XXX_value);
foo5<YYY> (char_value, int_value, XXX_value);
//===============================
cout << endl;
AAA aaa;
aaa.fooAAA1_1 ();
aaa.fooAAA1_2 ();
aaa.fooAAA1_3 ();
aaa.fooAAA2 (string_value, char_value);
aaa.fooAAA3 (string_value, char_value, XXX_value);
aaa.fooAAA3 (YYY_value, char_value, XXX_value);
aaa.template fooAAA4<YYY, int, string> ();
aaa.template fooAAA4<YYY, XXX, YYY> ();
aaa.template fooAAA5<int> (string_value, char_value, XXX_value);
aaa.template fooAAA5<YYY> (char_value, int_value, XXX_value);
//===============================
cout << endl;
BBB<int, char> bbb1;
bbb1.fooBBB1_1 ();
bbb1.fooBBB1_2 ();
bbb1.fooBBB1_3 ();
bbb1.fooBBB2 (string_value, char_value);
bbb1.fooBBB3 (string_value, char_value, XXX_value);
bbb1.fooBBB3 (YYY_value, char_value, XXX_value);
bbb1.template fooBBB4<YYY, int, string> ();
bbb1.template fooBBB4<YYY, XXX, YYY> ();
bbb1.template fooBBB5<int> (string_value, char_value,
XXX_value);
bbb1.template fooBBB5<YYY> (char_value, int_value, XXX_value);
//===============================
cout << endl;
BBB<XXX, int> bbb2;
bbb2.fooBBB1_1 ();
bbb2.fooBBB1_2 ();
bbb2.fooBBB1_3 ();
bbb2.fooBBB2 (string_value, char_value);
bbb2.fooBBB3 (string_value, char_value, XXX_value);
bbb2.fooBBB3 (YYY_value, char_value, XXX_value);
bbb2.template fooBBB4<YYY, int, string> ();
bbb2.template fooBBB4<YYY, XXX, YYY> ();
bbb2.template fooBBB5<int> (string_value, char_value,
XXX_value);
bbb2.template fooBBB5<YYY> (char_value, int_value, XXX_value);
//===============================
cout << endl;
bbb2.template fooBBB5<ZZZ> (bbb1, aaa, bbb2);
return 0;
}
//------------------- C++ code : END ----------------------
//#########################################################
//------------------- Running Results : BEGIN -------------
void foo1()
int foo2(const class string &, char)
void foo3<string, char, XXX>(const class string &, char &, class XXX)
void foo3<YYY, char, XXX>(const class YYY &, char &, class XXX)
void foo4<YYY, int, string>()
void foo4<YYY, XXX, YYY>()
int foo5<int, string, char, XXX>(const class string &, char &, class
XXX)
class YYY foo5<YYY, char, int, XXX>(const char &, int &, class XXX)
void AAA::fooAAA1_1()
void AAA::fooAAA1_2() const
static void AAA::fooAAA1_3()
int AAA::fooAAA2(const class string &, char)
void AAA::fooAAA3<string, char, XXX>(const class string &, char &, class
XXX)
void AAA::fooAAA3<YYY, char, XXX>(const class YYY &, char &, class XXX)
void AAA::fooAAA4<YYY, int, string>()
void AAA::fooAAA4<YYY, XXX, YYY>()
int AAA::fooAAA5<int, string, char, XXX>(const class string &, char &,
class XXX)
class YYY AAA::fooAAA5<YYY, char, int, XXX>(const char &, int &, class
XXX)
void BBB<int,char>::fooBBB1_1<int, char>() ### Attention ###
void BBB<int,char>::fooBBB1_2<int, char>() const ### Attention ###
static void BBB<int,char>::fooBBB1_3<int, char>() ### Attention ###
int BBB<int,char>::fooBBB2<int, char>(const class string &, char) ###
Attention ###
void BBB<int,char>::fooBBB3<string, char, XXX>(const class string &,
char &, class XXX)
void BBB<int,char>::fooBBB3<YYY, char, XXX>(const class YYY &, char &,
class XXX)
void BBB<int,char>::fooBBB4<YYY, int, string>()
void BBB<int,char>::fooBBB4<YYY, XXX, YYY>()
int BBB<int,char>::fooBBB5<int, string, char, XXX>(const class string &,
char &, class XXX)
class YYY BBB<int,char>::fooBBB5<YYY, char, int, XXX>(const char &, int
&, class XXX)
void BBB<XXX,int>::fooBBB1_1<XXX, int>() ### Attention ###
void BBB<XXX,int>::fooBBB1_2<XXX, int>() const ### Attention ###
static void BBB<XXX,int>::fooBBB1_3<XXX, int>() ### Attention ###
int BBB<XXX,int>::fooBBB2<XXX, int>(const class string &, char) ###
Attention ###
void BBB<XXX,int>::fooBBB3<string, char, XXX>(const class string &, char
&, class XXX)
void BBB<XXX,int>::fooBBB3<YYY, char, XXX>(const class YYY &, char &,
class XXX)
void BBB<XXX,int>::fooBBB4<YYY, int, string>()
void BBB<XXX,int>::fooBBB4<YYY, XXX, YYY>()
int BBB<XXX,int>::fooBBB5<int, string, char, XXX>(const class string &,
char &, class XXX)
class YYY BBB<XXX,int>::fooBBB5<YYY, char, int, XXX>(const char &, int
&, class XXX)
class ZZZ BBB<XXX,int>::fooBBB5<ZZZ, BBB<int,char>, AAA,
BBB<XXX,int>>(const class BBB<int,char> &, class AAA &, class
BBB<XXX,int>)
//------------------- Running Results : END ---------------
//#########################################################
//------------------- Environment -------------------------
g++ -v : gcc version egcs-2.91.57 19980901
(egcs-1.1 release)
uname -sr : SunOS 5.6
//---------------------------------------------------------
//#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Gcc-help
mailing list