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

erase() & erase_if() #21

Closed
samchon opened this issue Nov 15, 2018 · 1 comment
Closed

erase() & erase_if() #21

samchon opened this issue Nov 15, 2018 · 1 comment
Labels
C++20 enhancement New feature or request experimental Experimental Feature
Projects

Comments

@samchon
Copy link
Owner

samchon commented Nov 15, 2018

C++20 may define new functions, erase & erase_if in the <experimental/algorithm> module.

namespace std.experimental
{
    export function erase(container: Container<T>, val: T): Iterator<T>;
    export function erase_if(container: Container<T>, predicator: (val: T)=>boolean): Iterator<T>;
}
@samchon samchon added the C++20 label Nov 15, 2018
@samchon samchon added this to To do in v2.1 Update Nov 15, 2018
@samchon samchon moved this from To do to In progress in v2.1 Update Nov 16, 2018
@samchon samchon moved this from In progress to Done in v2.1 Update Nov 16, 2018
@samchon samchon closed this as completed Nov 30, 2018
@samchon samchon moved this from Done to To do in v2.1 Update Dec 11, 2018
@samchon samchon reopened this Dec 11, 2018
v2.1 Update automation moved this from To do to In progress Dec 11, 2018
@samchon samchon moved this from In progress to Done in v2.1 Update Dec 11, 2018
@samchon samchon moved this from Done to On review in v2.1 Update Dec 11, 2018
@samchon
Copy link
Owner Author

samchon commented Dec 11, 2018

I implemented the erase() & erase_if() functions under the v2.1 branch. However, I need to review it again. Is it proper to dividing conditional branches such like below?

  • export function erase_if<T>(container: any, predicator: (val: T)=>boolean): void
    {
    if (container.remove_if instanceof Function)
    container.remove_if(predicator);
    else if (container instanceof SetContainer || container instanceof MapContainer)
    {
    for (let it = container.begin(); !(it as any).equals(container.end()); )
    if (predicator(it.value))
    it = container.erase(it) as any;
    else
    it = it.next();
    }
    else
    {
    let it = remove_if(container.begin(), container.end(), predicator);
    container.erase(it, container.end());
    }
    }

@samchon samchon added the enhancement New feature or request label Dec 11, 2018
@samchon samchon moved this from On review to Done in v2.1 Update Dec 12, 2018
@samchon samchon closed this as completed Dec 12, 2018
@samchon samchon added the experimental Experimental Feature label Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++20 enhancement New feature or request experimental Experimental Feature
Projects
No open projects
v2.1 Update
  
Done
Development

No branches or pull requests

1 participant