dimanche 22 février 2015

Is there a way to remember(store) the return type of decltype?

I am storing the return values of a function call like this in a std::vector:


This is a very rough estimate



std::vector<boost::any> pressures;

Printer printerObs1;
Printer printerObs2;

const int initialPressure = 1;

auto pressure = MakeSubject<Pressure>(
BindObservers(printerObs1, printerObs2), initialPressure);//Return type Pressure<Printer, Printer> if I had passed three observers, the return type would have been Pressure<Printer, Printer, Printer> and so on

pressures.push_back(pressure); // This forgets the type.


If pressure were still in scope, I could easily say:



decltype(pressure) *p = boost::any_cast<decltype(pressure)>(&pressures[0]);

p->Change(1999); //class Pressure has a function called Change.


The question is, how do I remember the type of an auto that has been stored in an



std::vector<boost::any>


? AFAIK, decltype doesn't even return a value that can be stored?


So I need a container that can store a boost::any __and__ remember it's type


Aucun commentaire:

Enregistrer un commentaire