#include <set>
#include <algorithm>
#include <iostream>

class CountIt {
	public:
	CountIt() : storage(0), counter(0) {}
	CountIt& operator++()
	{
		++counter;
		return *this;
	}
    CountIt operator++(int)
	{
		CountIt oldValue = *this;
		return ++(*this);
	}
	int& operator*() { return storage;}
    int storage, counter;
};

int main()
{
    std::set<int> s1 { 1,2,3,4 };
    std::set<int> s2 { 3,4,5,6 };

   CountIt const & c = std::set_intersection(
        s1.begin(), s1.end(), s2.begin(), s2.end(),
        CountIt()
    );

    std::cout << c.counter;
}