Are you badass with C++ STL? Then fix this…
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <ostream>
#include <iterator>
using namespace std;
int main()
{
map<const char, int> A;
A['a'] = 0;
A['b'] = 5;
A['c'] = 10;
map<const char, int> B;
B['b'] = 105;
B['c'] = 110;
B['d'] = 115;
map<const char, int> C;
set_difference(A.begin(), A.end(), B.begin(), B.end(), less<char>, inserter(C, C.begin()) );
/*cout << "Set C (difference of A and B): ";
copy(C.begin(), C.end(), ostream_iterator<const char*>(cout, " "));
cout << endl;*/
}
<aeacides> lol
<aeacides> fulld: you reversed the order of the comparison functor with the insert iterator
<aeacides> set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin()), ltpairchar());
<fulld> aeacides: so basically… what you’re saying is I need more coffee :-)
<fulld> thanks
<aeacides> fulld: programmers are essentially machines which transform coffee into code
<fulld> I’m gonna blog that
▧
Comments
Discuss and share this topic anywhere. May we recommend:
- There is no official Twitter thread yet. Hit me up and I will make one.
- Please let me know any other good media coverage I should link here.
- Talk with me live every Tuesday 6pm (New York) at Community Service Hour.