This is just a sketch for the implementation of rank and select, eg. T should be replaced with const T& in real implementation and return value of rank could be selectable between index of where the not found item would be instead of -1 signalling not found.