digitalmars.D.learn - Are there some helpers in Phobos equivalent to std::set_difference of
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (15/15) Feb 03 2023 I could not find a thing doing this. And I don't want to write it
- Richard (Rikki) Andrew Cattermole (10/10) Feb 03 2023 ```d
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/14) Feb 03 2023 Thank you very much. I am surprised that I couldn't find it using
- Richard (Rikki) Andrew Cattermole (2/2) Feb 03 2023 All good, I'm glad it'll work for you :)
- =?UTF-8?Q?Ali_=c3=87ehreli?= (7/10) Feb 03 2023 'fold' is doing much better in that department because it mentions other...
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/4) Feb 03 2023 Ha ha! :) Make that 'reduce' of course.
I could not find a thing doing this. And I don't want to write it from scratch. Getting a range as output is ok too. What I need is the following: ```c++ const std::vector<int> v1{1, 2, 5, 5, 5, 9}; const std::vector<int> v2{2, 5, 7}; std::vector<int> diff; std::set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), std::inserter(diff, diff.begin())); print(v1, "∖ "); print(v2, "= "); print(diff, "\n"); // yielding { 1 2 5 5 5 9 } ∖ { 2 5 7 } = { 1 5 5 9 } ```
Feb 03 2023
```d import std.stdio, std.algorithm.setops, std.array; void main() { int[] v1 = [1, 2, 5, 5, 5, 9]; int[] v2 = [2, 5, 7]; int[] v3 = setDifference(v1, v2).array; writefln!"%s \\ %s = %s"(v1, v2, v3); } ``` [1, 2, 5, 5, 5, 9] \ [2, 5, 7] = [1, 5, 5, 9]
Feb 03 2023
On Friday, 3 February 2023 at 15:53:35 UTC, Richard (Rikki) Andrew Cattermole wrote:```d import std.stdio, std.algorithm.setops, std.array; void main() { int[] v1 = [1, 2, 5, 5, 5, 9]; int[] v2 = [2, 5, 7]; int[] v3 = setDifference(v1, v2).array; writefln!"%s \\ %s = %s"(v1, v2, v3); } ``` [1, 2, 5, 5, 5, 9] \ [2, 5, 7] = [1, 5, 5, 9]Thank you very much. I am surprised that I couldn't find it using many keywords on the site and google.
Feb 03 2023
All good, I'm glad it'll work for you :) I used the word difference to search the phobos docs with.
Feb 03 2023
On 2/3/23 08:01, Richard (Rikki) Andrew Cattermole wrote:All good, I'm glad it'll work for you :) I used the word difference to search the phobos docs with.'fold' is doing much better in that department because it mentions other names: "Implements the homonym function (also known as accumulate, compress, inject, or foldl) present in various programming languages of functional flavor." https://dlang.org/library/std/algorithm/iteration/reduce.html Ali
Feb 03 2023
On 2/3/23 09:11, Ali Çehreli wrote:'fold' isHa ha! :) Make that 'reduce' of course. Ali
Feb 03 2023