Opened 11 years ago
Closed 4 years ago
#6091 closed Bugs (fixed)
Not documented requirement about I/O operators
| Reported by: | Mateusz Loskot | Owned by: | Joel de Guzman |
|---|---|---|---|
| Milestone: | Boost 1.68.0 | Component: | fusion |
| Version: | Boost 1.47.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
The Fusion documentation in Boost 1.47 does not mention that in order to make Fusion-adapted types usable with input and output operators, it is necessary to import these operators into type's namespace.
The problem is discussed in the thread Adapted struct I/O.
Here is sample based on the demo::employee example that shows correct use of Fusion-adapted type:
#include <iostream>
#include <string>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/sequence/io.hpp>
#include <boost/fusion/include/io.hpp>
namespace demo
{
// This does the trick, but not documented
using boost::fusion::operators::operator<<;
using boost::fusion::operators::operator>>;
template<typename Name, typename Age>
struct employee
{
Name name;
Age age;
};
}
// Any instantiated demo::employee is now a Fusion sequence
BOOST_FUSION_ADAPT_TPL_STRUCT(
(Name)(Age),
(demo::employee) (Name)(Age),
(Name, name)
(Age, age))
int main()
{
demo::employee<std::string, int> e;
std::cin >> e;
std::cout << e << std::endl;
}
Change History (5)
comment:1 by , 11 years ago
| Component: | None → fusion |
|---|---|
| Owner: | set to |
comment:2 by , 11 years ago
comment:3 by , 11 years ago
I would care but I can not do it. I have clearly no idea where this should be added. IO chapter, Sequences chapter, near the demo example...does it apply to all sequences, are there any exceptions to this friend-ship rule, etc. I'm lacking of Fusion fu.
comment:4 by , 11 years ago
The thing is, this is more a C++ issue than it is a Fusion issue. It's about how ADL cannot happen if the types are in different namespaces. Perhaps a quick note somewhere in the demo is all that's needed.
comment:5 by , 4 years ago
| Milestone: | To Be Determined → Boost 1.68.0 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |

Would you care to submit a patch? :-) I'd be happy to apply one, if you do.