I understand that iota can be complex(e.g. infinite), so this can not be done easily in general case, but in some cases it should be possible to do find/contains operation in O(1).
For example
int main() {
auto vals = views::iota(10'000'000'000, 100'000'000'000);
return ranges::find(vals, 74'656'000'000) != vals.end();
}
runs "infinitely" (doing linear search) while
obviously check can be done in O(1).
Is there a way to do this generic way with C++(i.e. find/contains that on other views takes linear time, and when it detects iota it takes O(1)), or I need to manually detect when view passed to my function is finite iota view and do the >=front <=back
check?
find
would still need to do a linear operation, butcontains
could be specialised – Raulfind
from the question and just leavecontains
, for the reason explained in Caleth's comment. – Polisdict
is a range of keys, so havingkey in d
work is consistent - but in C++ our hashtables are ranges of pairs... – Australian