Skip to content

Commit

Permalink
Allow usage of const DictionaryList and reduce code size
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Jun 19, 2014
1 parent 0a41d3b commit eedc0cc
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions source/vibe/utils/dictionarylist.d
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,35 @@ struct DictionaryList(VALUE, bool case_sensitive = true, size_t NUM_STATIC_FIELD

/** Iterates over all fields, including duplicates.
*/
int opApply(int delegate(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] ){
if( auto ret = del(kv.key, 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 ){
if( auto ret = del(kv.key, 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 eedc0cc

Please sign in to comment.