From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Charles: missing default values
Date: 14 Nov 2002 08:16:56 -0800
Date: 2002-11-14T16:16:56+00:00 [thread overview]
Message-ID: <1ec946d1.0211140816.49731152@posting.google.com> (raw)
In-Reply-To: 3dd32396$0$308$bed64819@news.gradwell.net
porton@ex-code.com (Victor Porton) wrote in message news:<3dd32396$0$308$bed64819@news.gradwell.net>...
> It is reasonable to add default values to the arguments of
> many functions in charles, e.g. Genereic_Find for vectors would
> become:
>
> generic
> with function Predicate (Element : Element_Type)
> return Boolean is <>;
> function Generic_Find
> (Container : Container_Type;
> First : Index_Type'Base := First(C);
> Back : Index_Type'Base := Last (C)) return Index_Type'Base;
This won't compile. Where is C defined?
This isn't even correct, because the default value for Back is Last
(C), which is incorrect.
Note that there is a non-generic version of Find, that works by
comparing elements using the equality operator for Element_Type.
If you want an instantiation of Find that accepts only the container
as a parameter, then why don't you simply use a nesting subprogram:
function Find (V : Vector_Subtype) return Index_Subtype'Base is
procedure Find is new Generic_Find (Predicate);
begin
return Find (V, First (V), Back (V));
end;
Note also that this is a linear search. If your vector is sorted,
then you should be using Binary_Search or Lower_Bound.
prev parent reply other threads:[~2002-11-14 16:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-14 4:15 Charles: missing default values Victor Porton
2002-11-14 4:32 ` Hyman Rosen
2002-11-14 12:48 ` Marin David Condic
2002-11-14 15:56 ` Hyman Rosen
2002-11-14 16:23 ` Matthew Heaney
2002-11-14 7:18 ` Victor Porton
2002-11-14 16:16 ` Matthew Heaney [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