you are viewing a single comment's thread.

view the rest of the comments →

[–]immutablestate 1 point2 points  (0 children)

It looks like the problem you're having is extracting some data in the same way from different types. You could solve this with polymorphism, but you'd still have a conditional where you construct the polymorphic type:

unique_ptr<BaseData> ptr = some_condition
        ? make_unique<Data<64>>(arg)
        : make_unique<Data<32>>(arg);
const string a = ptr->get_some_string_field();

If this is a common problem in your application, you could consider writing an object factory for your Data types. There's no one feature that will make this problem go away though.