Skip to content

Commit

Permalink
std.internal.scopebuffer: added inout for slices
Browse files Browse the repository at this point in the history
update unittest

removed no-op cast

remove blank lines
  • Loading branch information
9il committed Sep 17, 2014
1 parent 39ed0b4 commit 83fab65
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions std/internal/scopebuffer.d
Expand Up @@ -199,7 +199,7 @@ struct ScopeBuffer(T, alias realloc = /*core.stdc.stdlib*/.realloc)
* A slice into the temporary buffer that is only
* valid until the next put() or ScopeBuffer goes out of scope.
*/
@system T[] opSlice(size_t lower, size_t upper)
@system inout(T)[] opSlice(size_t lower, size_t upper) inout
in
{
assert(lower <= bufLen);
Expand All @@ -212,7 +212,7 @@ struct ScopeBuffer(T, alias realloc = /*core.stdc.stdlib*/.realloc)
}

/// ditto
@system T[] opSlice()
@system inout(T)[] opSlice() inout
{
assert(used <= bufLen);
return buf[0 .. used];
Expand All @@ -222,7 +222,7 @@ struct ScopeBuffer(T, alias realloc = /*core.stdc.stdlib*/.realloc)
* Returns:
* the element at index i.
*/
ref T opIndex(size_t i)
ref inout(T) opIndex(size_t i) inout
{
assert(i < bufLen);
return buf[i];
Expand Down Expand Up @@ -352,6 +352,19 @@ unittest
assert(s == "hellobettyeven more");
}

// const
unittest
{
char[10] tmpbuf = void;
auto textbuf = ScopeBuffer!char(tmpbuf);
scope(exit) textbuf.free();
foreach(i; 0..10) textbuf.put('w');
const csb = textbuf;
const elem = csb[3];
const slice0 = csb[0..5];
const slice1 = csb[];
}

/*********************************
* This is a slightly simpler way to create a ScopeBuffer instance
* that uses type deduction.
Expand Down Expand Up @@ -391,4 +404,3 @@ unittest
c.put(s1);
c.put(s2);
}

0 comments on commit 83fab65

Please sign in to comment.