Created
May 30, 2018 21:11
-
-
Save ramntry/6dd854df918877f68beae917963f65b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <list> | |
template <typename T> | |
class Counter : public std::iterator<std::output_iterator_tag, T> { | |
size_t &Value; | |
public: | |
Counter(size_t &Result) : Value(Result) {} | |
const Counter &operator++() const { return *this; } | |
const Counter &operator*() const { return *this; } | |
void operator=(const T &Item) const { ++Value; } | |
}; | |
template <typename ForwardIt1, typename ForwardIt2> | |
size_t set_difference_size(ForwardIt1 First1, ForwardIt1 Last1, | |
ForwardIt2 First2, ForwardIt2 Last2) { | |
using OutputIt = Counter<typename ForwardIt1::value_type>; | |
size_t Result = 0; | |
std::set_difference(First1, Last1, First2, Last2, OutputIt(Result)); | |
return Result; | |
} | |
int main() { | |
std::list<int64_t> FirstList = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; | |
std::cout << set_difference_size(std::istream_iterator<int>(std::cin), | |
std::istream_iterator<int>(), | |
begin(FirstList), end(FirstList)) | |
<< std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment