stl algorithm replacement for the sake of lazy calculations