Re: [boost] [fusion][ping] how to initialize a container of non-const references to objects, from a container of objects

Hi Sorry for the slow reply, I had to think a bit about which approach I preferred. Does the attached code, using transform_view do what you need? I'm not comfortable adding non const ctors to vector for a few reasons, so I'd prefer this approach if possible. Thanks Dan ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/

Whoops... I overlooked this post - now we have a duplicate answer. dan marsden wrote:
Sorry for the slow reply, I had to think a bit about which approach I preferred.
Does the attached code, using transform_view do what you need?
Seems a bit nicer of a solution than what I suggested.
I'm not comfortable adding non const ctors to vector for a few reasons, so I'd prefer this approach if possible.
Still, it's just a workaround (IMHO) as it requires us to transform the whole sequence just because we can't keep it from getting const qualified. It certainly adds compile time overhead and I bet it even directly or indirectly infers code with some compilers. What about making the existing "Seq const & ctor" accept reference wrappers? Regards, Tobias

On 6/26/07, dan marsden <danmarsden@yahoo.co.uk> wrote:
Does the attached code, using transform_view do what you need? I'm not comfortable adding non const ctors to vector for a few reasons, so I'd prefer this approach if possible.
This works great, thanks! I did try a transform_view approach after I saw how views solved similar problems that were posted, but I must have been missing some piece of the puzzle in whatever I tried out because I couldn't get it to work at that point. So I really appreciate you posting a working example! Thanks, Stjepan

On 6/26/07, Stjepan Rajko <stipe@asu.edu> wrote:
On 6/26/07, dan marsden <danmarsden@yahoo.co.uk> wrote:
Does the attached code, using transform_view do what you need? I'm not comfortable adding non const ctors to vector for a few reasons, so I'd prefer this approach if possible.
This works great, thanks! I did try a transform_view approach after I
Found a case where it doesn't compile - adapting your example to how I'm using it: typedef fusion::vector<int, int> vec; vec v(1,2); fusion::transform_view<vec, make_ref> t(v, make_ref()); fusion::vector<int &, int &> vec_of_references(t); // this works fine, exactly what I need However, if I change this to: typedef fusion::vector<> vec; vec v; fusion::transform_view<vec, make_ref> t(v, make_ref()); fusion::vector<> vec_of_references(t); // does not compile The problem is that since vec_of_references is a vector of size 0 then it can't initialize from the transform_view because vector0 has no constructors defined (so only copy constructible). For sake of consistency, would it be possible to add a templated constructor to vector0 that could take a fusion sequence and do nothing with it? I'm using this from a templated class and it would be helpful if I didn't have to specially treat the size 0 case. Or, perhaps there is another simple solution I'm missing... :-) Thanks! Stjepan
participants (3)
-
dan marsden
-
Stjepan Rajko
-
Tobias Schwinger