[ create a new paste ] login | about

Link: http://codepad.org/plyTCBpx    [ raw code | fork ]

C++, pasted on Nov 29:
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/range/adaptor/map.hpp>
#include <QMap>
#include <arx/ext/qt/MapForeach.h>

int count;

class A {
public:
    A(): mValue(0) {}

    A(int value): mValue(value) {}
    
    int value() const {
        return mValue;
    }

    A(const A &other) {
        count++;
        mValue = other.mValue;
    }

    bool operator<(const A &other) const {
        return mValue < other.mValue;
    }

private:
    int mValue;
};


int main(int argc, char **argv) {
    
    QMap<A, A> m;
    m.insert(A(1), A(2));

    count = 0;
    BOOST_FOREACH(auto pair, m) {
        const A &key = pair.first;
    }
    std::cout << count << std::endl;

    count = 0;
    BOOST_FOREACH(const A &key, m | boost::adaptors::map_keys);
    std::cout << count << std::endl;

    return 0;
}


Create a new paste based on this one


Comments: