Timeline for Determine whether one vector is a prefix of the other
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 20, 2014 at 11:58 | comment | added | Nobody moving away from SE | I would also recommend to extract another function that does the prefix check assuming that the first entered vector is at most as long as the second and delegating to this from the one you already have. This will further reduce code duplication and make the code more readable. | |
Aug 19, 2014 at 18:16 | comment | added | Snowhawk | @nobody Remnants of my original response. Fixed. | |
Aug 19, 2014 at 18:15 | history | edited | Snowhawk | CC BY-SA 3.0 |
deleted 8 characters in body
|
Aug 19, 2014 at 11:19 | comment | added | Nobody moving away from SE |
Is there any reason why you are using cbegin instead of begin ? The vector s are const anyway so the latter will return the same and is shorter.
|
|
Aug 18, 2014 at 22:38 | history | edited | Snowhawk | CC BY-SA 3.0 |
added 138 characters in body
|
Aug 18, 2014 at 22:35 | comment | added | Snowhawk |
That appears to be very true, guess you have to check distances prior to checking for mismatch. Probably just easier to use your method of finding the minimum distance and passing the equivalent subsequences into std::equal() .
|
|
Aug 18, 2014 at 22:22 | comment | added | Jerry Coffin | At least as I read things, when you supply only three iterators, you must ensure that the third iterator points to the beginning of a sequence at least as long as the distance between the first two, or else you get undefined behavior. | |
Aug 18, 2014 at 22:05 | comment | added | Snowhawk | actually, I was thinking of a different function, you can just check if either iterator in the pair is the end. | |
Aug 18, 2014 at 22:04 | history | edited | Snowhawk | CC BY-SA 3.0 |
Cleaned up response based on Jerry's concern.
|
Aug 18, 2014 at 21:58 | history | edited | Snowhawk | CC BY-SA 3.0 |
Cleaned up response based on Jerry's concern.
|
Aug 18, 2014 at 21:48 | comment | added | Snowhawk |
I probably should have made the qualification that the OP would still have to prearrange their inputs or pay an extra cost in calculating/comparing distances post-std::mismatch() .
|
|
Aug 15, 2014 at 18:11 | history | answered | Snowhawk | CC BY-SA 3.0 |