c++ - implementation of traits with stl containers -


i have question concerning implementation of traits stl containers.

i have code should work different objects (with tensors in case) , have no direct access tensor class (for instance when use external tensor library). try realize necessary properties of tensors through traits.

for example, have template class should works tensor:

template<typename traits> class operator{   typedef typename traits::state_t state_t;   ......... }; 

it means particular tensor type should specify own traits type. instance sometensor do:

class sometensortraits{   typedef sometensor state_t;   ......... }; 

when want use other tensor type write traits:

class othertensortraits{   typedef othertensor state_t;   ......... }; 

then use different tensor types in same operator code , works fine.

problems start when want collect different tensors stl container (std::vector example). remind don't have access tensor classes (so can not make tensors derived base class) , don't want collect tensortraits in container.

thus question how collect different tensor objects through implementation of tensors in helper traits?

appreciate help.

you can use boost::any encapsulate objects. other way (more dirty) use union covers cases.

also can create ioperator class, derive , use vector<ioperator&> storing references.


Comments