I often want to grab the first element of an IEnumerable<T> in .net, and I haven’t found a nice way to do it. The best I’ve come up with is: foreach(Elem e in enumerable) { // do something with e break; } Yuck! So, is there a nice way to do this?
Category: c++
How do I get the first element from an IEnumerable
Rounding up to next power of 2
I want to write a function that returns the nearest next power of 2 number. For example if my input is 789, the output should be 1024. Is there any way of achieving this without using any loops but just using some bitwise operators?