Skip to content
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

Using emplace_* instead of push_* #1215

Open
irwir opened this issue Jun 24, 2023 · 4 comments
Open

Using emplace_* instead of push_* #1215

irwir opened this issue Jun 24, 2023 · 4 comments

Comments

@irwir
Copy link
Contributor

irwir commented Jun 24, 2023

emplace_* methods are more efficient when adding new objects, but might require C++11.
Does it make sense to add code for this?
Tests run successfully for the branch https://github.com/irwir/cryptopp/tree/use_emplace

@noloader
Copy link
Collaborator

Test the code with:

CXXFLAGS="-std=c++03" make -j 4

@irwir
Copy link
Contributor Author

irwir commented Jun 24, 2023

These flags are for GCC? I do not have it installed and almost always use Visual Studio, where currently the lowest possible seems to be /std:c++14
C++03 standards do not include emplace; it might be implemented but this could not be relied on.

@irwir
Copy link
Contributor Author

irwir commented Aug 13, 2023

This replacement could be done with a simple macro possibly named as CRYPTOPP_EMPLACE_BACK.
The definition may depend on CRYPTOPP_CXX11, or it could be a special CRYPTOPP_EMPLACE flag if necessary.

@irwir
Copy link
Contributor Author

irwir commented Oct 1, 2023

// emplace_front and emplace_back have been defined in C++11
#ifndef CRYPTOPP_CXX11_EMPLACE
#define CRYPTOPP_CXX11_EMPLACE 1
#endif

The idea is to add this definition into config_cxx.h at the end of CRYPTOPP_CXX11 block, and
after the CRYPTOPP_CXX11 block add CRYPTOPP_EMPLACE_BACK macro that expands to emplace_back or push_back method calls.

Is this good enough for a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants