It seems very useful to me.<br>By the way, is there a simple way to iterate through a fusion sequence or transformation of it with a python iterator? <br><br>Luca.<br><br><div class="gmail_quote">2009/2/27 Bruno Lalande <span dir="ltr"><<a href="mailto:bruno.lalande@gmail.com">bruno.lalande@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<br>
<br>
The topic below was opened in the Boost development mailing list,<br>
where it's been pointed out to me that it fits better here.<br>
<br>
You can also read the thread archive:<br>
<a href="http://thread.gmane.org/gmane.comp.lib.boost.devel/186573" target="_blank">http://thread.gmane.org/gmane.comp.lib.boost.devel/186573</a><br>
<br>
Regards<br>
Bruno<br>
<br>
<br>
---------- Forwarded message ----------<br>
<br>
<br>
Hello,<br>
<br>
I have written a little function that converts any Boost.Fusion<br>
sequence into a Python tuple (boost::python::tuple). If a sub-sequence<br>
is nested in the sequence, the result will also be a nested tuple (for<br>
instance, boost::make_tuple(0, std::make_pair(1, 2), 3) will give (0,<br>
(1, 2), 3) in Python).<br>
<br>
The source code is attached to this mail.<br>
<br>
The principle is that any sequence previously adapted to Boost.Fusion<br>
will become a tuple in Python. So, by including the right<br>
boost/fusion/adapted/xxx header, one can convert a pair, a tuple, a<br>
boost::array, and obviously any of the sequences provided by<br>
Boost.Fusion. For example:<br>
<br>
#include <boost/python.hpp><br>
#include <boost/fusion/adapted/std_pair.hpp><br>
#include <boost/fusion/adapted/boost_tuple.hpp><br>
#include <boost/fusion/container/generation/make_vector.hpp><br>
#include "make_tuple_from_fusion_sequence.hpp"<br>
<br>
using namespace boost::python;<br>
<br>
tuple from_sequence()<br>
{<br>
return make_tuple_from_fusion(<br>
boost::fusion::make_vector(<br>
1,<br>
std::make_pair("first", "second"),<br>
2,<br>
boost::make_tuple('a', 'b', 'c'),<br>
3<br>
)<br>
);<br>
}<br>
<br>
BOOST_PYTHON_MODULE(mymodule)<br>
{<br>
def("from_sequence", &from_sequence);<br>
}<br>
<br>
<br>
In Python we get:<br>
<br>
>>> import mymodule<br>
>>> mymodule.from_sequence()<br>
(1, ('first', 'second'), 2, ('a', 'b', 'c'), 3)<br>
<br>
<br>
Is there any interest in adding this function into Boost.Python? If<br>
yes, I can write the doc and tests, clean the source and maybe improve<br>
the implementation (for example, I feel that I could avoid the use of<br>
m_iteration with a better use of Boost.Fusion...).<br>
<br>
<br>
Regards<br>
<font color="#888888">Bruno<br>
</font><br>_______________________________________________<br>
Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org">Cplusplus-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">http://mail.python.org/mailman/listinfo/cplusplus-sig</a><br></blockquote></div><br><br clear="all"><br>-- <br>Ing. Luca Secchi<br>Ass.to Turismo, Artigianato e Commercio<br>
Servizio amministrativo e legale, del bilancio e degli affari generali <br>tel. interno 4312<br>tel. esterno 070/606 4312<br>