Swap two items in List

Check the answer from Marc from C#: Good/best implementation of Swap method. public static void Swap<T>(IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } which can be linq-i-fied like public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = … Read more

Why are there so many specializations of std::swap?

So what it is gained from specializing std::pair? Performance. The generic swap is usually good enough (since C++11), but rarely optimal (for std::pair, and for most other data structures). I’m also left wondering if I should be writing my own specializations for custom classes, or simply relying on the template version. I suggest relying on … Read more

Java method to swap primitives

I think this is the closest you can get to a simple swap, but it does not have a straightforward usage pattern: int swap(int a, int b) { // usage: y = swap(x, x=y); return a; } y = swap(x, x=y); It relies on the fact that x will pass into swap before y is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)