Skip to content

Commit

Permalink
Merge pull request #693 from BoapNet/const-dictionarylist
Browse files Browse the repository at this point in the history
Const opApply for DictionaryList
  • Loading branch information
s-ludwig committed Jun 19, 2014
2 parents 9a3c31e + eedc0cc commit 2a57cdf
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions source/vibe/utils/dictionarylist.d
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,35 @@ struct DictionaryList(VALUE, bool case_sensitive = true, size_t NUM_STATIC_FIELD

/** Iterates over all fields, including duplicates.
*/
int opApply(int delegate(ref string key, ref ValueType val) del)
int opApply(scope int delegate(string key, ref ValueType val) del)
{
foreach( ref kv; m_fields[0 .. m_fieldCount] ){
string kcopy = kv.key;
if( auto ret = del(kcopy, kv.value) )
foreach (ref kv; m_fields[0 .. m_fieldCount]) {
if (auto ret = del(kv.key, kv.value))
return ret;
}
foreach( ref kv; m_extendedFields ){
string kcopy = kv.key;
if( auto ret = del(kcopy, kv.value) )
foreach (ref kv; m_extendedFields) {
if (auto ret = del(kv.key, kv.value))
return ret;
}
return 0;
}

/// ditto
int opApply(int delegate(ref ValueType val) del)
int opApply(scope int delegate(ref ValueType val) del)
{
foreach( ref kv; m_fields[0 .. m_fieldCount] ){
if( auto ret = del(kv.value) )
return ret;
}
foreach( ref kv; m_extendedFields ){
if( auto ret = del(kv.value) )
return ret;
}
return 0;
return this.opApply((string key, ref ValueType val) { return del(val); });
}

/// ditto
int opApply(scope int delegate(string key, ref const(ValueType) val) del) const
{
return (cast() this).opApply(cast(int delegate(string, ref ValueType)) del);
}

/// ditto
int opApply(scope int delegate(ref const(ValueType) val) del) const
{
return (cast() this).opApply(cast(int delegate(ref ValueType)) del);
}

static if (is(typeof({ const(ValueType) v; ValueType w; w = v; }))) {
Expand Down

0 comments on commit 2a57cdf

Please sign in to comment.