skaller wrote:
> Obvious crap. Lvalueness of an iterator only affects whether it
> can be ++ incremented or not.
>
> An iterator which when dereferenced returns an lvalue is a different
> type to an iterator which when dereferenced returns merely an rvalue.
>
> In addition in C++ a const lvalue is distinct from a non-const one.
>
> To make matters worse, am STL map has a value which is a struct
> type with one const and one non-const element.
gotcha. So then shouldn't the Iterator's deref be "it -> t", and have
the lvalue specified in the typeclass constructor? I'm not sure what one
would do to distinguish something like "val x: int = deref cin" which
could return an int, but it wouldn't make sense to return a reference,
and an array where you would want to return the reference so that you
could manipulate the value stored inside? Would we have to manually
store the manipulated value? Something like:
val x:int = deref it;
x += 1;
store (it, x);
It could be nice if we could do "*it += 1;", but "*cin += 1" would not.
>> typeclass Writable_iterator[it,t] {
>> virtual proc store: &it -> t;
>> }
>
> This is just wrong, the correct signature is
>
> virtual proc store: it * t;
>
> Whether or not a particular iterator supports storing
> will determine whether to instantiate it under this
> typeclass.
Ah, my mistake. Does this have sugar attached to it that mandates a
particular form? would that be the "*it = x" form?
>> typeclass Swappable_iterator[it,t] {
>> virtual proc iter_swap: &it -> ⁢
>> }
>
> Not sure I understand this: iterators are always swappable.
Maybe I miswrote the function. It's supposed to say that you can swap
the values the iterator points two.
> Whether the value they point at are swappable depends on whether
> the iterator types are Writable_iterator's (in your classification).
> You can always implement swap using a temporary in that case ..
> so swap method should probably be added to Writable_iterator,
> in case there is a more efficient way to do it.
The iterators need to be readable as well, as the Writable_iterator
ought to provide no mechanism for pulling data out of the iterator. For
instance, a "cout" style iterator can't access the data you write into
it, as it's already written across the stream. However, I didn't inherit
Writable_iterator and Readable_iterator in case there was an
instance-specific way to do the swapping. I did provide a generic
Swappable that provides the generic case (tmp-swap), but I'm not sure if
that would actually work.
-e
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language