From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: When to use formal discrete type?
Date: Wed, 29 Nov 2017 15:05:59 -0600
Date: 2017-11-29T15:05:59-06:00 [thread overview]
Message-ID: <ovn7fn$rk8$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: ovn0bv$1rto$1@gioia.aioe.org
"Victor Porton" <porton@narod.ru> wrote in message
news:ovn0bv$1rto$1@gioia.aioe.org...
...
> It there a noticeable difference in performance if I generalize?
That clearly is compiler specific, and also specific to how the type is
used.
Janus/Ada, for example, uses generic sharing, so the code generated for a
formal discrete type and a formal private type are very different. (In most
cases, the formal private type will win, but not if there are a lot of
components of that type).
OTOH, GNAT generally uses template expansion. In such a case, the final code
isn't much different than if you had written it yourself without using the
generic. So it probably doesn't matter much.
The main difference is the promise given to the instantator. A private type
implies that any non-limited type will work (assuming that it has the
operations given in the generic spec). So you may want to consider what
happens if someone instantiates your generic with some record type. If that
would be a real problem, then the formal discrete type would be better (as
it better documents what actually works).
Randy.
prev parent reply other threads:[~2017-11-29 21:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 19:04 When to use formal discrete type? Victor Porton
2017-11-29 19:43 ` Shark8
2017-11-29 21:07 ` Dmitry A. Kazakov
2017-11-29 21:05 ` 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