Skip to content

Remove <algorithm> dependency from from_json.hpp #4734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

vittorioromeo
Copy link

As discussed on Reddit, here's a PR taking a first small step towards the improvement of compilation times. Avoiding dependencies on "heavy" standard library header such as <algorithm> can help.

Here is the ClangBuildAnalyzer compilation time report:
https://gist.github.com/vittorioromeo/7a89a1e9af8cb89ee217d4e85be83270

@vittorioromeo vittorioromeo requested a review from nlohmann as a code owner April 11, 2025 15:17
@github-actions github-actions bot added the L label Apr 11, 2025
@coveralls
Copy link

Coverage Status

coverage: 99.187% (+0.001%) from 99.186%
when pulling 8bf6d54 on vittorioromeo:develop
into 7ddea26 on nlohmann:develop.

@nlohmann
Copy link
Owner

@vittorioromeo Thanks for the PR! Could you please sign off your commit (see https://github.com/nlohmann/json/pull/4734/checks?check_run_id=40403948884).

@gregmarr
Copy link
Contributor

gregmarr commented Apr 15, 2025

Rather than rewrite all of these algorithms which have been in production for many years, and potentially break the use on a user-defined type that specializes std::front_insert_iterator or std::insert_iterator, I wonder if it would be better to just create a local version of transform (and since it's just used for the side effects, not the return, it's really a copy_transform, so it could be renamed):

template<class InputIt, class OutputIt, class UnaryOp>
void copy_transform(InputIt first1, InputIt last1,
                   OutputIt d_first, UnaryOp unary_op)
{
    for (; first1 != last1; ++d_first, ++first1)
        *d_first = unary_op(*first1);
}

based on "Possible Implementation" from https://en.cppreference.com/w/cpp/algorithm/transform

Copy link

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants