deferred class EL_CHAIN [G]
inherit
CHAIN [G]
feature -- Basic operations
order_by (sort_value: FUNCTION [G, COMPARABLE]; in_ascending_order: BOOLEAN)
-- sort all elements according to `sort_value' function
local
l_item: G; new_index: INTEGER
do
if not off then
l_item := item
end
across ordered_by (sort_value, in_ascending_order) as v loop
put_i_th (v.item, v.cursor_index)
if v.item = l_item then
new_index := v.cursor_index
end
end
if new_index > 0 then
go_i_th (new_index)
end
ensure
same_item: (old off) or else (old item) = item
end
end
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/36e03d19-aa20-4336-96b6-09f988e4cbcd%40googlegroups.com.
Perhaps using 'index' in the postcondition might work?
same_item: old off or else old (if off then Void else item end) = item
That won't compile on 16.05 but a good suggestion. I came up with
an equivalent
ensure
same_item: old off or else old item_or_void = item
end
item_or_void: like item
do
if not off then
Result := item
end
end
Cheers Eric!
-- SmartDevelopersUseUnderScoresInTheirIdentifiersBecause_it_is_much_easier_to_read
(attached (old off) as al_old_off and then old_off) or else ( (old_item) = item)
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/E24E5DA0-5536-4357-8552-4D6E66882985%40gmail.com.
> Could you post the implementation of your item function? could be helpful to find a workaround
same_item: old off or else old item_or_void =
item
item_or_void: like item
do
if not off then
Result := item
end
end
Introduces an old expression. Old expressions are valid only in the postconditions of routines.