Open gnzlbg opened 8 years ago
Also, for single "range" views, most of them do
is_finite<Rng>::value ? finite : range_cardinality<Rng>::value
. I wonder whyrange_cardinality<Rng>::value
isn't enough here.
Some ranges know at compile time not only that they are finite but also how many elements they have (e.g., view::single
). The range cardinality can be used to express that. is_finite
tests for both cases: finite but unknown at compile-time (e.g. std::vector
) or finite with a particular value.
EDIT: Range cardinality was a bit of an experiment. I'm not particularly happy with the amount of complexity it introduces. It's nice to tell the finite ranges apart from the infinite ranges, but even that may not be worth it.
Are there other "common" cardinalities that one often needs on sets of ranges?
I'm not sure how common this use case is, but for the domain I tend to do work in, it's advantageous to know at compile time that a range's size is bounded by some constant. Exploiting this kind of static information enables optimizations such as loop unrolling and locating data in registers. For example, these kinds of optimizations are essentially mandatory for writing competent GPU algorithm libraries. I wouldn't be surprised to find these sorts of considerations in other domains. It would be nice if there was an elegant way to reason about range cardinalities that are stronger than finite and unknown but weaker than some particular finite value.
Interesting! Thanks for the information. We value this kind of domain-specific experience.
When writing a new
view
it is very common to need to compute the cardinality of a set of ranges. For example:view::concat
("weakest" cardinality): if any range is infinite, then infinite, otherwise if any range is unknown -> unknown, otherwise if all ranges are finite -> finite.view::zip_with
("strongest" cardinality): if any range is finite -> finite, if any range is unknown -> unknown, if all ranges are infinite -> infinite.Do you think it is worth it to add general utilities for these? For example could these utilities be reused to compute "more complex" cardinalities easier (like
view::join
's cardinality?).Are there other "common" cardinalities that one often needs on sets of ranges?
Also, for single "range" views, most of them do
is_finite<Rng>::value ? finite : range_cardinality<Rng>::value
. I wonder whyrange_cardinality<Rng>::value
isn't enough here.