Skip to main content
added 11 characters in body
Source Link
G. Sliepen
  • 69.5k
  • 3
  • 75
  • 180

Try to match the conventions of the STL

Your algorithms are getting more generalgeneric. Consider that you would want to use thisyour algorithms in code that also uses regular STL algorithms. Then it is a bit annoying that you are using a different naming convention. At this point, I think it would be helpful to match the conventions of the STL. I would name the function recursive_transform(), since recursive is a bit more precise than all. Try to make it look like std::ranges::transform().

Your earlier implementations could also be made more generic; for example instead of having separte nested sum and nested max functions, make an algorithm that looks like std::reduce().

Avoid making copies of the input

In this part of the code:

std::transform(_input.begin(), _input.end(), returnObject.begin(),
    [_Func](auto element)->auto
    {
        return TransformAll(element, _Func);
    }
);

You are passing element by value. Since element might be a nested container, that means you are copying potentially a huge amount of memory. This should be auto &element.

Also note that the ->auto return type is redundant.

Try to match the conventions of the STL

Your algorithms are getting more general. Consider that you would want to use this in code that also uses regular STL algorithms. Then it is a bit annoying that you are using a different naming convention. At this point, I think it would be helpful to match the conventions of the STL. I would name the function recursive_transform(), since recursive is a bit more precise than all. Try to make it look like std::ranges::transform().

Your earlier implementations could also be made more generic; for example instead of having separte nested sum and nested max functions, make an algorithm that looks like std::reduce().

Avoid making copies of the input

In this part of the code:

std::transform(_input.begin(), _input.end(), returnObject.begin(),
    [_Func](auto element)->auto
    {
        return TransformAll(element, _Func);
    }
);

You are passing element by value. Since element might be a nested container, that means you are copying potentially a huge amount of memory. This should be auto &element.

Also note that the ->auto return type is redundant.

Try to match the conventions of the STL

Your algorithms are getting more generic. Consider that you would want to use your algorithms in code that also uses regular STL algorithms. Then it is a bit annoying that you are using a different naming convention. At this point, I think it would be helpful to match the conventions of the STL. I would name the function recursive_transform(), since recursive is a bit more precise than all. Try to make it look like std::ranges::transform().

Your earlier implementations could also be made more generic; for example instead of having separte nested sum and nested max functions, make an algorithm that looks like std::reduce().

Avoid making copies of the input

In this part of the code:

std::transform(_input.begin(), _input.end(), returnObject.begin(),
    [_Func](auto element)->auto
    {
        return TransformAll(element, _Func);
    }
);

You are passing element by value. Since element might be a nested container, that means you are copying potentially a huge amount of memory. This should be auto &element.

Also note that the ->auto return type is redundant.

Source Link
G. Sliepen
  • 69.5k
  • 3
  • 75
  • 180

Try to match the conventions of the STL

Your algorithms are getting more general. Consider that you would want to use this in code that also uses regular STL algorithms. Then it is a bit annoying that you are using a different naming convention. At this point, I think it would be helpful to match the conventions of the STL. I would name the function recursive_transform(), since recursive is a bit more precise than all. Try to make it look like std::ranges::transform().

Your earlier implementations could also be made more generic; for example instead of having separte nested sum and nested max functions, make an algorithm that looks like std::reduce().

Avoid making copies of the input

In this part of the code:

std::transform(_input.begin(), _input.end(), returnObject.begin(),
    [_Func](auto element)->auto
    {
        return TransformAll(element, _Func);
    }
);

You are passing element by value. Since element might be a nested container, that means you are copying potentially a huge amount of memory. This should be auto &element.

Also note that the ->auto return type is redundant.