T
the.rubist
hi all
i have to components:
- a third-party (math) lib with namespaces
- a new lib with templates
i would merge this two components together. is there a way to customize
the namespace in a template ?
the code at the bottom is compilable. the results are:
10
10
but i would the following results:
10
0
i would configurable the namespace "Math" in the template. what's the
way to doing this ?
#include <iostream>
using namespace std;
namespace Single {
float compute( float a ) {
return a + a;
}
}
namespace Double {
double compute( double a ) {
return a - a;
}
}
namespace Math = Single;
template < typename T >
class Foo
{
public:
T call(T a) {
return Math::compute( a );
}
};
int main (int argc, char * const argv[]) {
{
namespace Math = Single;
Foo<float> f;
cout << f.call(5.0) << "\n";
}
{
namespace Math = Double;
Foo<double> f;
cout << f.call(5.0) << "\n";
}
}
regards,
the.rubist
i have to components:
- a third-party (math) lib with namespaces
- a new lib with templates
i would merge this two components together. is there a way to customize
the namespace in a template ?
the code at the bottom is compilable. the results are:
10
10
but i would the following results:
10
0
i would configurable the namespace "Math" in the template. what's the
way to doing this ?
#include <iostream>
using namespace std;
namespace Single {
float compute( float a ) {
return a + a;
}
}
namespace Double {
double compute( double a ) {
return a - a;
}
}
namespace Math = Single;
template < typename T >
class Foo
{
public:
T call(T a) {
return Math::compute( a );
}
};
int main (int argc, char * const argv[]) {
{
namespace Math = Single;
Foo<float> f;
cout << f.call(5.0) << "\n";
}
{
namespace Math = Double;
Foo<double> f;
cout << f.call(5.0) << "\n";
}
}
regards,
the.rubist