mardi 29 mars 2016

std::vector of std:tuples not being affected by emplace_back and push_back

For a class that maps addresses to I/O devices I have the following types:

typedef std::tuple<addr_t, addr_t, std::shared_ptr<IDeviceIO> > IODeviceEntry;
typedef std::vector<IODeviceEntry> IODeviceMap;

class IDeviceIO {
    public:
        virtual ~IDeviceIO(){}
        virtual int read(addr_t addr, data_t *data, data_t *ws) = 0;
        virtual int write(addr_t addr, data_t *data, data_t *ws, data_t size) = 0;
};

And the following methods to 1) add entries and 2) show connected devices:

void connectDevice(addr_t from, addr_t to, std::shared_ptr<IDeviceIO> d) {
        try {
            m_iomap.emplace_back( std::forward_as_tuple(from, to, d) );
        } catch (std::exception& e) {
            std::cerr << "Exception! " << e.what() << std::endl;
        }
}

void showConnectedDevices() {
    std::cout << boost::format("I/O Device Map (%d devices)") % m_iomap.size() << std::endl;
    for(auto it= m_iomap.cbegin(); it != m_iomap.cend(); ++it) {
        std::string name = "N/D";
        std::cout << boost::format("{0x%08x, 0x%08x} -> %s") % std::get<0>(*it) %
                                                               std::get<1>(*it) %
                                                               name << std::endl;
    }
}

What I don't understand is why after calling connectDevice() no exception is thrown, but vector is not updated.

Is there anything I may be missing? (note: also tried with push_back, and obtained the same result)

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire