improve site legality tests
Following Sean Parent's advice, rewrite a manual loop to use an algorithm, and refactor the body of the original loop
into a predicate.

This also reduces the complexity of the site checking algorithm - the predicate runs in constant instead of linear time.
use boost::iterator_range instead of std::pair<iter_t, iter_t> for compatibility with C++11 ranges