[phoenix] std::fstream problem

Hi there, sorry to bother the community with my phoenix problems today. Please consider the following code sample: #include <boost/spirit/include/phoenix_algorithm.hpp> #include <boost/spirit/include/phoenix_bind.hpp> #include <boost/spirit/include/phoenix_container.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_function.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_scope.hpp> #include <boost/spirit/include/phoenix_statement.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <algorithm> #include <iostream> #include <fstream> #include <vector> int _tmain(int argc, _TCHAR* argv[]) { using namespace std; using namespace boost::phoenix; using namespace boost::phoenix::arg_names; vector< int > ints; ofstream out( ".\\remove.txt" ); // works std::for_each( ints.begin(), ints.end(), cout << arg1 << " " ); // doesn't work - error C2297: '<<' : illegal, right operand has type 'const char *' std::for_each( ints.begin(), ints.end(), out << arg1 << " " ); return 0; } I couldn't find anything inside the documentation regarding file streams. Thanks, Christian

std::for_each(ints.begin(), ints.end(), boost::phoenix::ref(out) << arg1 << ' '); AFAIK, phoenix gives std::cout special treatment in regards to being implicitly captured by reference.

Adam, thanks a lot. That worked. But when extending to my "real world" use case I'm running constantly into troubles. There are still some issues with file streams. cout mostly works but ofstream doesn't. Attached is a file with my use cases. These are very basic usages of phoenix and I think they should work. Thanks, Christian On Wed, Nov 5, 2008 at 3:08 PM, Adam Merz <adammerz@hotmail.com> wrote:
std::for_each(ints.begin(), ints.end(), boost::phoenix::ref(out) << arg1 << ' ');
AFAIK, phoenix gives std::cout special treatment in regards to being implicitly captured by reference.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christian Henning wrote:
Adam, thanks a lot. That worked. But when extending to my "real world" use case I'm running constantly into troubles. There are still some issues with file streams. cout mostly works but ofstream doesn't.
Attached is a file with my use cases. These are very basic usages of phoenix and I think they should work.
Thanks, Christian
On Wed, Nov 5, 2008 at 3:08 PM, Adam Merz <adammerz@hotmail.com> wrote:
std::for_each(ints.begin(), ints.end(), boost::phoenix::ref(out) << arg1 << ' ');
AFAIK, phoenix gives std::cout special treatment in regards to being implicitly captured by reference.
Wouldn't it be easier/more appropriate to provide extraction operator overload for your point struct and then just: std::copy( pts.begin() , pts.end() , std::ostream_iterator<point>(out, "\n")); The point members could be streamed using transform_iterators. Jeff
participants (3)
-
Adam Merz
-
Christian Henning
-
Jeff Flinn