tqdm.cpp icon indicating copy to clipboard operation
tqdm.cpp copied to clipboard

Proposal for new class

Open CrazyPython opened this issue 9 years ago • 4 comments

This idea might be crazy, maybe, I don't know.

Currently, in order to add a progress bar to a classic for loop, they'd have to change something like this:

for (int i = 0; i < 10; ++i) {
    // ...
}

into this:

for (int i : trange(10)) {
    // ...
}

That might be a little bit of a hassle and might ruin the code's style in the eye of the user. So I propose a small class that lets you replace it with this:

for (tqdm::whatever i = 0; i < 10; ++i) {
    // ...
}

I wrote a little bit of code to this effect:

class twhatever {
    tqdm foo;
    int value;
 public:
    inline twhatever(int initial) {
        value = initial;
        foo = tqdm(initial);  // or whatever intialization
    }
    inline operator int() const {return value;}
    twhatever inline operator++ () {
        value++;
        foo.update(1);
        return *this;
    }
};

It implicitly converts to an integer (not usually good, but great in this case) and the ++ operator updates the bar. Add the other postfix/prefix decrement/increment, and it's good to go.

It would make implementing progress bars just that little bit easier.

My writing is a bit sloppy and came out in reverse. I think it's a good idea.

What do you guys think? And I can implement this myself if it is decided as such, it's a pretty simple task.

CrazyPython avatar Aug 19 '16 15:08 CrazyPython

@o11c thoughts?

CrazyPython avatar Aug 22 '16 21:08 CrazyPython

I think this is a substantial improvement.

CrazyPython avatar Aug 22 '16 21:08 CrazyPython

@casperdcl ...

CrazyPython avatar Sep 03 '16 17:09 CrazyPython

The problem with this is you don't give tqdm a total even though one is clearly available. That means no bar and eta

casperdcl avatar Sep 04 '16 19:09 casperdcl