Re: [eigen] Signed or unsigned indexing

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


> 
> On 20 Jan 2017, at 16:54, Francois Fayard <fayard@xxxxxxxxxxxxx> wrote:
> 
> Let me give you my 2 cents on this signed/unsigned problem:
> 
> - The core C++ language is using signed integers for indexing. If p is a pointer, p[k] is defined for k being a std::ptrdiff_t which is the Index type used by Eigen
> - The C++ standard library is using unsigned integers for indexing: std::size_t

actually, std random access iterators do accept signed indices as well. size_t indices are used at the container level only.
This actually makes sense to me, considering that interfaces should be minimal and that unsigneds has a simpler
set of invalid values when representing non negative quantities ( signeds need to specify the behaviour of
passing two bounds instead of one,  this increases the complexity of documentation, pre/postcondition checks and tests ).

premising that I’m definitely in the signed party,  I think most signed/size_t interoperability problems come from using
containers when iterators/ranges/views should be used; in my experience ( for what it’s worth :) ) if containers decays to views
ASAP most unsigned to signed indices conversions disappear, leaving just few controlled casts/checks where appropriate.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/