Would you write the following simple container any other way or it’s totally sensible as it is:
template <typename T, bool small_>
struct TransType
{
typedef const T& param_type;
};
template <typename T>
struct TransType<T, true>
{
typedef const T param_type;
};
template <class T>
class Container:public TransType<T,sizeof(T)<=sizeof(void*)> {
public:
param_type getVal(){
return obj;
}
void setVal(param_type input){
containment=input;
}
private:
T containment;
};
Look into Boost.CallTraits. Namely,
boost::call_traits<T>::param_type.You shouldn’t need the client to specify whether the type is small or not, that’s the metafunction’s job. Nor is there really a need to inherit from anything.
In fact your code right now is ill-formed. Because
param_typeisn’t a dependent type, the lookup is done without taking into consideration the base class; and will not be found. You’d need to either explicitly qualify it with the base class, add a using-directive, or re-typedef it.You just want to end up with:
By:
Now the condition is automatic, and there’s no base class hassle.