Add features about adding/inserting multiple elements or array content#12
Open
Lasereyes5 wants to merge 1 commit intoMashpoe:masterfrom
Open
Add features about adding/inserting multiple elements or array content#12Lasereyes5 wants to merge 1 commit intoMashpoe:masterfrom
Lasereyes5 wants to merge 1 commit intoMashpoe:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for creating this simple and useful library.
I try to use the char vector as string with this library, but it lacks some features. I think these features will also be helpful in dealing array and multiple elements, so I implement them.
I don't know if you need or want these features, so feel free to judge.
Added Symbols
These are macros and functions added:
Disadventages
The macro
vector_add_multipleandvector_insert_multipleuses two C99 features called "Variadic Macros" and "Compound Literals" to accept multiple elements and create a temprory array, basicly like this:I haven't test it in MSVC (or C++ in MSVC) yet, so I don't know if this will causes problems.
The descriptions and names about these actions are quite long to fit the sheets in README file, may get a mess or force other lines align longer.Adventages
Add/Insert multiple items or array content directly:
Now I can use the char vector as string more easily:
It even supports adding/inserting structs directly, since I uses memcpy to implement this instead of
forloop.It uses like this:
Note: I thought it would causes problems to make temporary structs in macro, but it eventually works in a tricky way.
For example, the struct arguments in
vector_add_multiple(&size_vec, (size){-65,39}, (size){12,-87});will break down into"(size){-65" "39}" "(size){12" "-87}", and join back again in__VA_ARGS__. So this won't affect any structure in arguments even with structs.