Rotating contents of a matrix (vector) to the left or right Each vector element is a row and each character is a column.
Assume the matrix is square (N*N) and N is &lt; 10.

I have some code to do it but it doesn't look great and would love some feedback on how to make it better. You can use any function of the C++ standard library. The only constraint is it can't be in-place. I'm looking to improve it in style and any optimisations needed.
enum DIRECTION
{
    DIR_RIGHT = 0,
    DIR_LEFT = 1
};
    
vector&lt;string&gt; rotate(const vector&lt;string&gt;&amp; original, DIRECTION direction)
{
    vector&lt;string&gt; rotated(original);
    for (vector&lt;string&gt;::const_iterator irow = original.begin(); irow != original.end(); ++irow) {
        int new_col = direction == DIR_RIGHT ? (original.size() - 1) - (irow - original.begin())
                                             : (irow - original.begin());
        for (string::const_iterator icol = (*irow).begin(); icol != (*irow).end(); ++icol) {
            int new_row = direction == DIR_RIGHT ? (icol - (*irow).begin())
                                                 : ((*irow).size() - 1) - (icol - (*irow).begin());
            rotated[new_row][new_col] = *icol;
        }
    }
    return rotated;
}

Example input:
&quot;###&quot;
&quot;oho&quot;
&quot;ooo&quot;

Rotating right should output:
&quot;oo#&quot;
&quot;oh#&quot;
&quot;oo#&quot;

P.s. For convenience I've included using namespace std;, the final code uses the namespace explicitly E.g. std::vector.
I didn't look very closely at the algorithm, so I'll trust that it is correct ;)

Some stylistic changes you could do are:


Use auto to clean up those long iterator names.
Break long lines. Shorter lines are usually easier to digest.
DIRECTION is a bit unusual for the name of an enum type. That notation is normally used for the enum constants, the type usually goes with the same notation used for classes and structs (CamelCase, in most projects).
Use const as much as possible. Making the integer indexes const in this case won't change much, but making things that are not supposed to change const is a good habit, so you should aways try to do it, even for small sections of code. You never know when that tiny function might grow.


Following is a snippet of code with the above changes applied:

enum Direction
{
    DIR_RIGHT = 0,
    DIR_LEFT  = 1
};

std::vector&lt;std::string&gt; rotate(const std::vector&lt;std::string&gt;&amp; original, Direction direction)
{
    std::vector&lt;std::string&gt; rotated(original);

    for (auto irow = original.cbegin(); irow != original.cend(); ++irow) {

        const auto new_col = (direction == DIR_RIGHT) ?
            (original.size() - 1) - (irow - original.cbegin()) :
            (irow - original.cbegin());

        for (auto icol = (*irow).cbegin(); icol != (*irow).cend(); ++icol) {

            const auto new_row = (direction == DIR_RIGHT) ?
                (icol - (*irow).cbegin()) :
                ((*irow).size() - 1) - (icol - (*irow).cbegin());

            rotated[new_row][new_col] = *icol;
        }
    }

    return rotated;
}


Side note: You might also want to check out std::distance() to replace the iterator diferences you are computing with operator -.

Also, by using cbegin()/cend(), you can ensure the returned iterators are of type const_iterator and thus pointing to immutable data.