7

I know I can user erase to clear the table, but this method only clear one data at a time and must write a action to do that. Is there any easy way to do that?

4

You can use the following implementation:

template<uint64_t A, typename B, typename... C> void clear_table(multi_index<A, B, C...>* table) {
    auto it = table->begin();
    while (it != table->end()) {
        it = table->erase(it);
    }
}
|improve this answer|||||
  • Could you please elaborate about the parameters you are passing, and what they are ? – Damir Olejar Jul 15 '18 at 4:54
  • @DisplayName, A,B,C are template parameters of multi_index, u can look them up in multi_index.hpp. A - is a table name, B - is a struct, stored in table, C - is indices list. You don't need to pass them, you just pass a table and params will be deducted – baltazar Jul 16 '18 at 7:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.