From 0a41d3b642cd5ded861ab495034a2eeb318e113f Mon Sep 17 00:00:00 2001 From: Geod24 Date: Wed, 18 Jun 2014 17:07:25 -0700 Subject: [PATCH 1/2] Remove workaround for old compiler issue (2443) --- source/vibe/utils/dictionarylist.d | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/vibe/utils/dictionarylist.d b/source/vibe/utils/dictionarylist.d index 4a2c356fa7..01d2b3042d 100644 --- a/source/vibe/utils/dictionarylist.d +++ b/source/vibe/utils/dictionarylist.d @@ -184,16 +184,14 @@ 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(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) ) + 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) ) + if( auto ret = del(kv.key, kv.value) ) return ret; } return 0; From eedc0ccc3f3bc555e2f5918fa65cdc5dd6247652 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Wed, 18 Jun 2014 19:43:57 -0700 Subject: [PATCH 2/2] Allow usage of const DictionaryList and reduce code size --- source/vibe/utils/dictionarylist.d | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/source/vibe/utils/dictionarylist.d b/source/vibe/utils/dictionarylist.d index 01d2b3042d..767d86ef94 100644 --- a/source/vibe/utils/dictionarylist.d +++ b/source/vibe/utils/dictionarylist.d @@ -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; }))) {