Count unique elements in each row of a matrix using std::set to automatically handle duplicates and return the count.