On 7/20/2011 3:40 AM, Nathan Ridge wrote:
The docs:
http://www.boost.org/doc/libs/1_47_0/libs/fusion/doc/html/fusion/adapted/std...
seem to suggest that one can pipe an adapted std::pair 'directly' to cout.
I find the following though:
#include <iostream> #include <boost/fusion/adapted.hpp> // adapt pair. #include <boost/fusion/sequence.hpp> // operator<<() ? #include <boost/fusion/container.hpp> // as_vector
int main(int argc, char** argv) { std::pair<std::string, int> p("foo", 7);
std::cout << p << std::endl; // does not compile although docs suggest it should. std::cout << boost::fusion::as_vector(p) << std::endl; // compiles and works as expected.
return 0; }
Am I missing an include? Is sending to cout without first using as_vector actually supported?
Hmm... well boost/fusion/sequence/io/out.hpp (which is included by boost/fusion/sequence/io.hpp which is in turn included by boost/fusion/sequence.hpp) does define the correct operator<< for all sequences, but it's in the boost::fusion namespace, and I don't see it being exported into the global namespace anywhere.
If you add "using boost::fusion::operator<<;" to your code, it works fine.
But this seems to be in contradiction with the docs, which say [1] (emphasis mine):
The **global** |operator<<| has been overloaded for generic output streams such that Sequence <http://www.boost.org/doc/libs/1_47_0/libs/fusion/doc/html/fusion/sequence.html>(s) are output by recursively calling |operator<<| for each element.
Perhaps the authors were relying on ADL to find operator<<, but overlooking the fact that not all sequences would be in the boost::fusion namespace?
Thanks. That's certainly not correct. Adapted sequences in other namespaces can't avail of that. I just fixed the docs to avoid further confusion. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com