Set fusion::vector value with boost::shared_ptr

Hello alltogether, I've posted this already in Stackoverflow a week ago with no answer up to now, so I thougth I try it here again. I want to set a value in a fusion::vector at a specific location. This works normaly very well with fusion::at_c(seq) = value, as at_c returns a reference to the object at this position. However, this is not garanted, the documentation only states about the return type: "In most cases, this is a reference". I've encounterd a case where it is not a reference, when the objects are of type boost::shared_ptr<anytype>. Therefore I cant set the values as I'm only overriding a temporary. Minimal example: struct Object1{}; struct Object2{}; typedef fusion::vector<boost::shared_ptr<Object1>, boost::shared_ptr<Object2>
seq_type;
seq_type seq; boost::shared_ptr<Object1> value(new Object1()); fusion::at_c<0>(seq) = value; assert(fusion::at_c<0>(seq) ); //assert will be executed because the default constructed empty pointer was not overridden with a valid one BOOST_MPL_ASSERT(( boost::is_reference< result_of::at_c<seq_type, 0>::type > )) //compilation fails because the returned type is not a reference What is a valid alternative of setting the pointers in an fusion sequence? Any help would be appreciated! Thanks, Stefan

Stefan Troeger <stefantroeger@gmx.net> writes:
I want to set a value in a fusion::vector at a specific location. This works normaly very well with fusion::at_c(seq) = value, as at_c returns a reference to the object at this position. However, this is not garanted, the documentation only states about the return type: "In most cases, this is a reference". I've encounterd a case where it is not a reference, when the objects are of type boost::shared_ptr<anytype>. Therefore I cant set the values as I'm only overriding a temporary. Minimal example:
Please post a minimal but functional sample next time. That said, I cannot reproduce your problem with the current boost trunk and gcc 4.7.0. Christopher

On Sunday 15 April 2012 17:30:17 Christopher Schmidt wrote:
Stefan Troeger <stefantroeger@gmx.net> writes:
I want to set a value in a fusion::vector at a specific location. This works normaly very well with fusion::at_c(seq) = value, as at_c returns a reference to the object at this position. However, this is not garanted, the documentation only states about the return type: "In most cases, this is a reference". I've encounterd a case where it is not a reference, when the objects are of type boost::shared_ptr<anytype>. Therefore I cant set the values as I'm
only overriding a temporary. Minimal example: Please post a minimal but functional sample next time. That said, I cannot reproduce your problem with the current boost trunk and gcc 4.7.0.
Hello Christopher, sorry for not posting a fully functional example. Seeing your code working showed that the problem was within my fusion sequence creating and not withnin fusion. Changed that now and everything works in my program. Thank you very much for your help. Stefan
participants (2)
-
Christopher Schmidt
-
Stefan Troeger