

//
// SequenceHandle
//

record SequenceHandle[A] (
    inner : Pointer[A]
);

[A]
overload LightweightSequence?(static SequenceHandle[A]) = true;

[A]
overload ContiguousSequence?(static SequenceHandle[A]) = true;

[A | CallDefined?(UnderlyingContainerConstructor, Static[A])]
overload UnderlyingContainerConstructor(static SequenceHandle[A]) =
    UnderlyingContainerConstructor(A);



//
// sequenceHandle
//

[A | Sequence?(A)]
inline sequenceHandle(seq:A) = SequenceHandle(&seq);



//
// sequence operations
//

[A, ..ARGS | CallDefined?(iterator, A, ..ARGS)]
inline overload iterator(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..iterator(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(reverseIterator, A, ..ARGS)]
inline overload reverseIterator(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..reverseIterator(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(size, A, ..ARGS)]
inline overload size(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..size(seq.inner^, ..args);

[A | CallDefined?(StaticSize, Static[A])]
inline overload StaticSize(static SequenceHandle[A]) = StaticSize(A);

[A, ..ARGS | CallDefined?(index, A, ..ARGS)]
inline overload index(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..index(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(begin, A, ..ARGS)]
inline overload begin(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..begin(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(end, A, ..ARGS)]
inline overload end(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..end(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(front, A, ..ARGS)]
inline overload front(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..front(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(back, A, ..ARGS)]
inline overload back(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..back(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(push, A, ..ARGS)]
inline overload push(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..push(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(pop, A, ..ARGS)]
inline overload pop(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..pop(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(clear, A, ..ARGS)]
inline overload clear(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..clear(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(insert, A, ..ARGS)]
inline overload insert(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..insert(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(remove, A, ..ARGS)]
inline overload remove(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..remove(seq.inner^, ..args);

[A, ..ARGS | CallDefined?(reserve, A, ..ARGS)]
inline overload reserve(seq:SequenceHandle[A], forward ..args:ARGS)
    = forward ..reserve(seq.inner^, ..args);
