Re: [eigen] Signed or unsigned indexing |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Signed or unsigned indexing
- From: Massimiliano Janes <max.jns@xxxxxxxxx>
- Date: Fri, 20 Jan 2017 17:53:55 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=lo8eJOQzxBxygQbNTDocibaWyOrRAP+CUChQdzR9OGw=; b=OPZVUcxHvExs/CtAlFM2ZyDEs5HBDtKbZtgInKQHRtb5n8fGt9xr8izc+d7zANQydS rvnSdrk7R2XEgbJYZ28ucaLq+lseHqBB32thpvXqxPbwhCGEkkiKWN2Ye2poT1imqozr sUR4dWS+HYfgGtzM6HU7PkNXZmCsn+thXDLjNXPBWaCosRMcixjb/J/P6uTnfuD7RXf8 neoVUXz4/avnyBDxYc6i8M5dsbF503Yx4ixpjT6xOWUJuq3HPdr5M+5tddnsh5QvG8em 2UTTunui6AR7gBe3aZaeUZrD0v6gHFMyeIr/qYzqYYpnyOJD/gJxfbc2rXPw390dOWvr fREg==
>
> 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.