Skip to content

Commit

Permalink
Add helper method to call the progress bar with only a range object a…
Browse files Browse the repository at this point in the history
…nd a lambda function.
  • Loading branch information
geektoni authored and iglesias committed Apr 12, 2018
1 parent 32a6746 commit d8c84e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/shogun/base/progress.h
Expand Up @@ -739,5 +739,16 @@ namespace shogun
{
return PRange<T>(range, *sg_io, prefix, mode, condition);
}

/** Creates @ref PRange given a range that uses the global SGIO
*
* @param range range used
* @param condition premature stopping condition
*/
template <typename T>
inline PRange<T> progress(Range<T> range, std::function<bool()> condition)
{
return PRange<T>(range, *sg_io, "PROGRESS: ", UTF8, condition);
}
};
#endif /* __SG_PROGRESS_H__ */
13 changes: 13 additions & 0 deletions tests/unit/base/PRange_unittest.cc
Expand Up @@ -126,6 +126,19 @@ TEST(PRange, lambda_stop)
EXPECT_EQ(test, 3);
}

TEST(PRange, lambda_stop_shorter_method)
{
int test = 6;
/* Stops before the 4th iteration */
for (auto i : progress(range(0, 6), [&]() { return test > 3; }))
{
(void)i;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
test--;
}
EXPECT_EQ(test, 3);
}

TEST(PRange, DISABLED_progress_incorrect_bounds_positive)
{
range_io.enable_progress();
Expand Down

0 comments on commit d8c84e9

Please sign in to comment.