>> You mean the first type in the sequence of value types that is convertible from the argument? That's possible, but I don't believe boost::variant presently attempts to do that. You can always try!
Or, maybe can’t ) (I really have a user’s knowledge/attitude to variant).
>> Hmmm...then why are you using variant?Because I need a single type as an output from my various templates.Say you are solving a PDE. And your various PDE classes contain (coefficient) functions of all kinds ( contstants, zeros etc.) Then I want to have a unique typeas an output. A variant seemed like a good idea. The type of the function is known at compile time. I just don’t want to carry around O(N^2) types where N the dimensionality of the PDE- and this is just for the cross terms.
>>Well, variant essentially erases the type of the object it's constructed with, so you're effectively using runtime polymorphism (though of a more controlled nature than boost::any or virtual functions). I don't know enoughabout the particulars of your application based on your description above to know if that's appropriate.Here is a problem to understand what I am thinking of (only for info purposes, no purpose of cluttering you):Say, I have a vector Monte-Carlo engine that advances likeV(t_dt) = m*dt * sigma*Fi*zeta*randomwhere now m, sigma, Fi, zeta can be zero or one and have various classes that produce them. I want to have a single class for the advancement (actually there are various different classes dependent on the numerical method).Now, I can use expression templates for them, but there are significant gains if I know that certain type are fixed (say, m = 0 and/or zeta = 1 ).This is why I want to ba able to have these functions in a controlled manner (they are only a few of those, so a variant seems natutral.The same with a PDE example.
What I really need is some variant type that encapsulates what I described above. The number of calls to the subscript operator is going to be in the millions. (btw this is what I call opimized)
PS: No offense to anyone, but the documentation is a bit obscure. I think there would be a certain benefit, if in the documentation there was some info on implementation issues, to allow peopleto make more educated decisions.
Maybe it is my fault, but after having spent some time with it, I still do not know what is contained in the data structure ( copies, references/pointers-to-external objects, who knows),
what are the guarantees of compile-time variant etc.