There is no good way to compare AR [I]. A [A] and AR [I] B. B?
Int a [10], b [10]; Square fu {int A, b; }; Foo ARR [10]; I can do the following:
For (i = 0; i <10; i ++) {if (A [ I] == arr [i] .a {} if (b [i] == arr [i] .b) {}} But, it is very painful, especially If there are several areas, and if () conditionally performs the same thing more then many codes will be duplicated. What I really want to do is parametrize it by any means and call a function (eg test (a, arr)) I think I can solve it using the #define macros, but it seems ugly.
Any suggestions?
In addition to this, I want to avoid creating a new array of FU objects because I do not want to create a new object, which can have many fields which I do not care about, I would like to compare various sub-related associations.
If the classes are of the same size, with a predicate (or a lambda) std :: equals Use:
bool Compa (int lhs, foo rhs) {return lhs == rhs.A; }; ... // to check the result of Equality Bull = std :: equal (A, A + 10, arr, CompA); ... // to see if the std :: pair & lt; Int *, Foo * & gt; Result = std :: mismatch (A, A +10, ARR, compa); Size_t index = result. First - A; If (index & lt; 10) {std :: cout & lt; & Lt; "Mismatch on Index" & lt; & Lt; Index & lt; & Lt; "A =" & lt; & Lt; * result. First & lt; & Lt; "Foo.a =" & lt; & Lt; (* Result. Seconds). & Lt; & Lt; Std :: endl; }
Comments
Post a Comment