P
Pavel
I am trying to make library code use a type specified by the library
user, if he defines it in a typedef, and another type, if s/he doesn't,
something as in the code below (which does not compile as it is).
What's the simplest API for this from the perspective of library user?
Ideally a user that does not need the flexibility of choosing his own
Type does not have to pay for it in terms of API complexity.
Thank in advance,
-Pavel
#include <iostream>
using namespace std;
template<typename T>
struct TC // provided by library
{
static void DefaultF() { cout << "Default F()\n"; }
};
struct Concrete { /*...*/ }; // some Concretes are provided by library,
some by user.
template<>
struct TC<Concrete>
{
static void ConcreteF() { cout << "Concrete F()\n"; }
};
struct HaveTypedef { typedef double Type; /* ... */ }; // provided by user
template<typename T>
struct TC<typename T::Type> {
static void HaveTypedefF() { cout << "Have typedef F(): " <<
T::Type() << '\n'; }
};
int
main()
{
TC<int>:efaultF();
TC<double>::HaveTypedefF();
TC<Concrete>::ConcreteF();
return 0;
}
user, if he defines it in a typedef, and another type, if s/he doesn't,
something as in the code below (which does not compile as it is).
What's the simplest API for this from the perspective of library user?
Ideally a user that does not need the flexibility of choosing his own
Type does not have to pay for it in terms of API complexity.
Thank in advance,
-Pavel
#include <iostream>
using namespace std;
template<typename T>
struct TC // provided by library
{
static void DefaultF() { cout << "Default F()\n"; }
};
struct Concrete { /*...*/ }; // some Concretes are provided by library,
some by user.
template<>
struct TC<Concrete>
{
static void ConcreteF() { cout << "Concrete F()\n"; }
};
struct HaveTypedef { typedef double Type; /* ... */ }; // provided by user
template<typename T>
struct TC<typename T::Type> {
static void HaveTypedefF() { cout << "Have typedef F(): " <<
T::Type() << '\n'; }
};
int
main()
{
TC<int>:efaultF();
TC<double>::HaveTypedefF();
TC<Concrete>::ConcreteF();
return 0;
}