Мое предпочтение состояло бы в том, чтобы просто оценить условие и передать результат вместо того, чтобы передать выражение, которое будет оценено и параметр, на котором можно оценить его. Кроме того, я предпочитаю иметь способность настроить все сообщение. Обратите внимание, что это просто предпочтения - я не говорю, что Ваш образец является неправильным - но существуют некоторые случаи, где это очень полезно.
Helper.Validate( firstName != null || !string.IsNullOrEmpty(directoryID),
"The value for firstName cannot be null if a directory ID is not supplied." );
This may be unrelated to your segmentation fault, but...
In C++, your "compare" predicate must be a strict weak ordering. In particular, "compare(X,X)"
must return "false" for any X. In your compare function, if both pairs are identical, you hit the test (p1.first <= p2.first)
, and return "true". Therefore, this "compare" predicate does not impose a strict weak ordering, and the result of passing it to "sort" is undefined.
Try using all the values from n = 32766
up to 32770
. I suspect you'll find that you are experiencing some sort of overflow. This is because 2^15 (32768) is the biggest number that can be represented using 16 bits (assuming you also allow negative numbers). You will have to use a different data type.
Suggestion:
Get it to output the vector's maxsize:
cout << p.max_size();
Let us know what that does. All things being normal, I'd expect it to be in the hundreds of millions (536870911 on my computer). But if it's more like 32768, then that could be the problem.