Opened 7 years ago

Closed 5 months 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 Changed 7 years ago by anonymous

Component: Nonefusion
Owner: set to Joel de Guzman

comment:2 Changed 7 years ago by Joel de Guzman

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

comment:3 Changed 7 years ago by Mateusz Loskot

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 Changed 7 years ago by anonymous

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 Changed 5 months ago by Kohei Takahashi

Milestone: To Be DeterminedBoost 1.68.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.