From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Empty Bounded Containers
Date: Fri, 23 May 2014 16:45:33 -0500
Date: 2014-05-23T16:45:33-05:00 [thread overview]
Message-ID: <lm06os$b58$3@loke.gir.dk> (raw)
In-Reply-To: cfe5082c-9b50-4c5b-afe1-8dd6ea1640b9@googlegroups.com
<sbelmont700@gmail.com> wrote in message
news:cfe5082c-9b50-4c5b-afe1-8dd6ea1640b9@googlegroups.com...
...
>which is not intuitively what I would assume. For instance, the following
>line:
>
>x : BC.Vector (Capacity => 42) := BC.Empty_Vector;
The problem here is using ":=" on bounded containers. Because of the
capacity discriminant, it will never work quite right.
The whole reason that Assign and Copy were introduced into the Ada 2012
containers is to work around this problem.
You want:
X : BC.Vector (Capacity => 42) := Copy(BC.Empty_Vector, Capacity => 42);
Or:
X : BC.Vector (Capacity => 42);
BC.Assign (Target => X, Source => BC.Empty_Vector);
Ada has no way to avoid discriminant checks in ":=", so there is no
possibility of making it work like you would want.
Randy.
prev parent reply other threads:[~2014-05-23 21:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 0:20 Empty Bounded Containers sbelmont700
2014-05-23 1:05 ` Adam Beneschan
2014-05-27 14:50 ` Adam Beneschan
2014-05-27 20:59 ` sbelmont700
2014-05-23 6:00 ` Simon Wright
2014-05-23 15:37 ` Adam Beneschan
2014-05-23 17:54 ` Simon Wright
2014-05-23 21:45 ` Randy Brukardt [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox