I'm writing a library and wonder what's the best practise for datatypes used in a public API.
Given the funtion
void foo (int bar)
which expects an index to some internal array/container. What type should that be? Because an index can never be negative I could use unsigned int or size_t. Or should I stick with a plain int and assert / throw if some invalid value is provided?
In general: Should I choose a type based on the valid data range (e.g. to avoid negative checks) or not?
EDIT: another example, suppose my library provides a function for printing a file. The user can choose the range of pages to be printed:
void print (int page_from, int page_to)