I wonder whether there is a (legal) way to obtain the size of a tbb::task_list.
I would like to write a little template class that implements a continuation task, using CRTP to do the actual work. The simplest way to do this seems to get the size of a tbb::task_list for setting the correct ref_count, see attached sample code.
Btw, wouldn't it be nice if tbb comes with little helper classes like this?
there is no easy way to get the task list size from the information currently stored in it. Either task count would need to be maintained within the class (if backward compatibility allows) or the method to get size would need to traverse the list and count the tasks. Perhaps the latter would be acceptable for a typical small task list; if it's of any help, I think we can implement it.
However, looking at your implementation, I think a much easier way to achieve what you need would be for the split() method to return a pair that contains the task list and its length. Not the nicest way but not bad as well I think, and it would work with any TBB version.
Since the tasking API in TBB is essentially just exposed implementation detail of how the algorithms are built on top of a work stealing scheduler, it was developed for efficiency, not for convenience. A user-friendly task API would need to be designed very differently. I am not sure if such helper classes would really help much, but we will gladly accept your work if you contribute it, and at least make it publicly available at our Web site for those who can be interested.