RE: [Boost-users] Re: Question

Thanks for help,
I have an additional question. Does anyone know why the following
program gives different output on VC++ 6 and VC++ 2003 NET? It is pretty
strange, isn't it?
Thanks in advance.
Pshemek
#include <iostream>
#include <cmath>
using namespace std;
class A
{
protected:
char m_d;
};
class B : public A
{
public:
typedef char s;
private:
unsigned short g;
};
class C : public A
{
public:
typedef short unsigned s;
private:
unsigned d;
};
template<bool cond>
class Select {};
template<> class Select<true>
{
static void Statment1(double g)
{
cout << g*g << endl;
}
public:
static void f(double g)
{
Statment1(g);
}
};
template<> class Select<false>
{
static void Statment2(double g)
{
cout << sqrt(g) << endl;
}
public:
static void f(double g)
{
Statment2(g);
}
};
template<bool cond> void exec()
{
Select<cond>::f(3.0);
}
template<class T>
void foo()
{
exec
I would like to write a template which depending on the argument type does different things.
For example the pseudo code:
template
foo(T& nT, C& nC) { // common code; if(T==C) // specific code; ..... // again common code; }
Can the template meta programming help me in this case?
It may. It depends on whether "specific code" compiles when T!=C. If it
does, you could do this:
template

Sliwa, Przemyslaw (London) wrote:
Thanks for help,
I have an additional question. Does anyone know why the following program gives different output on VC++ 6 and VC++ 2003 NET? It is pretty strange, isn't it?
<snip> VC6 is pretty strange, I agree. In particular, it doesn't handle functions with non-type template parameters well. The following code should demonstrate the problem. (Hopefully I'm remembering the problem correctly -- I don't have VC6 installed on this machine.) template<int I> void foo() { std::cout << I << '\n'; } int main() { foo<1>(); foo<2>(); return 0; } If you must use VC6, avoid non-type template parameters for function templates. -- Eric Niebler Boost Consulting www.boost-consulting.com
participants (2)
-
Eric Niebler
-
Sliwa, Przemyslaw (London)