Std.algorithm.copy and std.digest

When I use std.algorithm.copy on std.digest , I get different results compared to the put byte byte byte. Why?

 import std.stdio; import std.digest.digest; import std.digest.md; import std.algorithm; void main() { string s = "Hello!\n"; auto d1 = makeDigest!MD5; auto d2 = makeDigest!MD5; foreach (ubyte b; s) { d1.put(b); } s.copy(d2); writeln(digest!MD5(s).toHexString); writeln(d1.finish().toHexString); writeln(d2.finish().toHexString); } 

Output:

 E134CED312B3511D88943D57CCD70C83 E134CED312B3511D88943D57CCD70C83 D41D8CD98F00B204E9800998ECF8427E 
+5
source share
1 answer

d2 is passed by value for copying. Data is copied inside the function, but then when it returns, the d2 variable is unmodified from the outside!

I seem to think that this might be a mistake: the current behavior does not make much sense to me. When you copy it, it makes sense to do this by reference. Unities only test arrays that are semi-references (they are pointers) and they work for them.

+4
source

Source: https://habr.com/ru/post/1245044/


All Articles