Ad
  • Custom User Avatar

    I keep doing the same thing if the first thing I would do would be to make an exact copy. The thing is the argument passed by value is just your local copy and you can do whathever you want with it without having it an effect for the caller. For the caller it matters little whether you take const & and do a copy explicitly or take argument by value. No changes are visible outside of a function.

  • Custom User Avatar

    Vector v is being initialized inside function move_zeroes in this case.
    Is it correct to return a reference to an object which will be destroyed after leaving this function?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Modulo by a constant { 2^n } will be optimised by the compiler to (x & (2^n-1)) anyway, and x % 2 makes the intention clearer.

    $ echo "f(unsigned int i) { return i % 16; }" | gcc -O3 -xc - -S -o- 2>/dev/null | sed -n /f:/,/endproc/p
    f:
    .LFB0:
    .cfi_startproc
    movl %edi, %eax
    andl $15, %eax
    ret
    .cfi_endproc

  • Default User Avatar