fork download
#include 

namespace named
{
	template
	void sort_it_it(RandomIt first, RandomIt last)
	{
		(void) last;
		(void) (first + 1);
		(void) (bool(*first < *first));
		// stuff...
	}
	
	template
	void sort_cont_cmp(Container& c, Compare cmp)
	{
		typename Container::iterator b = c.begin(), e = c.end();
		(void) e;
		(void) (b + 1);
		(void) (bool(cmp(*b, *b)));
		// stuff...
	}
}

namespace overloaded
{
	template
	void sort(RandomIt first, RandomIt last)
	{
		puts("sort(RandomIt, RandomIt)");
		named::sort_it_it(first, last);
	}
	
	template
	void sort(Container& c, Compare cmp)
	{
		puts("sort(Container&, Compare)");
		named::sort_cont_cmp(c, cmp);
	}
}

struct BadContCmp { // Not complete. Bad.
	int x[10];
	
	BadContCmp() { for (int i = 0; i < 10; ++i) x[i] = 42; } // LOL.
	
	typedef int * iterator;
	iterator begin() { return x; }
	iterator end()   { return x + 10; }
	
	typedef bool result_type;
	typedef int first_argument_type;
	typedef int second_argument_type;
	bool operator()(int const& a, int const& b) const { return a < b; }
};

int main()
{
	BadContCmp contcmp;
	
	named::sort_it_it(contcmp.begin(), contcmp.end()); // ok (of course)
	named::sort_cont_cmp(contcmp, contcmp); // ok (of course)
	
	overloaded::sort(contcmp.begin(), contcmp.end()); // ok
	//overloaded::sort(contcmp, contcmp); // error (inside the body of sort_it_it)
}
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
sort(RandomIt, RandomIt)