Recursively defined lambda functions in C++11

A neat feature, which was introduced in since C++11 is the ability to define a lambda functions[1] in combination with delegates represented by std::function[2]. The following exemplary code snippet demonstrates how a recursive lambda function can be constructed this way:

#include <functional>
#include <iostream>

int main () {
  std::function<void(int)> count_down;

  count_down = [&count_down] (int num) -> void {
    if (num > 0) {
      std::cout << "i:" << num << std::endl;
      
      count_down (num - 1);
    }
  };

  count_down (6);
}

Using GCC, the above code can be compiled with:

$ g++ testcase.cpp -o testcase --std=c++11

[1] http://en.cppreference.com/w/cpp/language/lambda
[2] http://en.cppreference.com/w/cpp/utility/functional/function

Quickly applying patches on Gentoo

Sometimes, it’s necessary to apply a patch for a given package and there is no time and no desire to fork an ebuild to a custom overlay. Luckily Gentoo provides an easy way to so. All you need to do is to place a patch into the directory /etc/portage/patches/[category]/[ebuild’s name]/new-fix.patch. Sadly, not all ebuilds in the portage tree has a build-in support for this feature and to be on the safe side you can put the following hook into the portage’s bashrc file:

# cat /etc/portage/bashrc 
post_src_prepare() {
    if type epatch_user &> /dev/null ; then
    	epatch_user
    fi
}

Reference: Gentoo wiki

Enabling multilib abi_x86_32 support on the stable Gentoo system

Currently the abi_x86_32 use flag is masked on the stable Gentoo system. Therefore turning the 32 option in the ABI_X86 variable, will not bring you further:

# cat /etc/portage/make.conf
...
ABI_X86="32 64"
...

and as a result the line

# emerge --ask --verbose --newuse --update --deep world

will show you an endless number of conflicts, which can not be directly resolved by portage. If you never the less wish to enable the 32 bit library support on your system, especially to make your 32 bit applications running well under wine, you should force the abi_x86_32 desired use flag. One of the possible solutions to achieve this would be:

# cat /etc/portage/profile/use.mask 
-abi_x86_32

Moreover, more additional packages are required to have a full multilib featured support. Many of them has not been marked as stable yet. An up to date list of this packages at the moment of writing can be found here:

# cat /etc/portage/package.keywords/multilib
=x11-libs/libxcb-1.9*
=x11-libs/xpyb-1.3.1-r3
=dev-libs/libusb-1.0.9-r2
=sys-libs/e2fsprogs-libs-1.42.7-r1
=sys-fs/e2fsprogs-1.42.8

=media-libs/libjpeg-turbo-1.3.0-r2 
=media-libs/libdvdnav-4.2.0-r1 
=media-libs/a52dec-0.7.4-r7 
=media-libs/libmpeg2-0.5.1-r2 
=sys-apps/attr-2.4.47-r1 
=media-sound/musepack-tools-465-r1 
=net-libs/libasyncns-0.8-r3 
=virtual/jpeg-0-r2 
=media-libs/libtheora-1.1.1-r1 
=media-sound/pulseaudio-4.0-r1 
=media-libs/webrtc-audio-processing-0.1-r1 
=dev-libs/fribidi-0.19.5-r2 
=app-arch/bzip2-1.0.6-r4 
=sys-libs/libavc1394-0.5.4-r1 
=media-libs/libid3tag-0.15.1b-r4 
=dev-libs/udis86-1.7-r2 
=media-sound/jack-audio-connection-kit-0.121.3-r1 
=media-sound/twolame-0.3.13-r1 
=media-libs/libdvdread-4.2.0-r1 
=media-plugins/alsa-plugins-1.0.27-r1 
=dev-libs/libcdio-paranoia-0.90_p1-r1 
=media-sound/gsm-1.0.13-r1 
=sys-libs/e2fsprogs-libs-1.42.8 
=dev-libs/json-c-0.11-r1 
=dev-libs/libpcre-8.33-r1 
=virtual/libusb-0-r1 
=sys-apps/dbus-1.6.18-r1 
=dev-libs/libusb-compat-0.1.5-r2 
=media-libs/faac-1.28-r4 
=media-libs/libsidplay-1.36.59-r1 
=media-libs/ladspa-sdk-1.13-r2 
=media-libs/libmms-0.6.2-r1 
=media-libs/libmad-0.15.1b-r8 
=sys-devel/llvm-3.3-r1 
=media-libs/libmikmod-3.3.3 
=virtual/libiconv-0-r1 
=sys-libs/gdbm-1.10-r1 
=media-libs/libmodplug-0.8.8.4-r1 
=sys-libs/gpm-1.20.7-r2 
=media-plugins/alsaequal-0.6-r1 
=media-libs/libsndfile-1.0.25-r1 
=media-libs/libdvdcss-1.2.13-r1 
=virtual/glu-9.0-r1 
=media-libs/libiec61883-1.2.0-r1 
=app-admin/eselect-cdparanoia-0.1 
=media-libs/flac-1.2.1-r5 
=media-video/ffmpeg-0.10.10 
=media-libs/libsamplerate-0.1.8-r1 
=media-libs/xvid-1.3.2-r1 
=media-libs/speex-1.2_rc1-r2 
=media-libs/libao-1.1.0-r2 
=media-libs/x264-0.0.20130912 
=dev-libs/gmp-5.1.3-r1 
=media-libs/libdca-0.0.5-r3 
=media-libs/libsidplay-2.1.1-r4 
=app-text/libpaper-1.1.24-r2 
=virtual/libusb-1-r1 
=media-libs/glu-9.0.0-r1 
=media-sound/cdparanoia-3.10.2-r6 
=media-libs/libcuefile-477-r1 
=media-libs/libv4l-1.0.0 
=x11-libs/libvdpau-0.7 
=media-sound/lame-3.99.5-r1 
=media-libs/alsa-lib-1.0.27.2 
=media-libs/freeglut-2.8.1-r1 
=dev-libs/libffi-3.0.13-r1 
=virtual/libffi-3.0.13-r1 
=sys-libs/libraw1394-2.1.0-r1 
=media-sound/wavpack-4.60.1-r1 
=media-libs/libreplaygain-477-r1 
=dev-libs/libcdio-0.90-r1 
=sys-libs/ncurses-5.9-r3 
=x11-proto/dri2proto-2.8-r1 
=media-plugins/caps-plugins-0.9.15 
=dev-libs/liboil-0.3.17-r2 
=media-libs/faad2-2.7-r3 
=sys-libs/libieee1284-0.2.11-r3 
=dev-libs/elfutils-0.156 
=media-libs/mesa-9.2.4 
=sys-apps/tcp-wrappers-7.6.22-r1 
=virtual/opengl-7.0-r1 
=media-libs/glew-1.10.0-r2 
=media-plugins/swh-plugins-0.4.15-r3 
=media-libs/libvisual-0.4.0-r3 
=media-libs/vo-aacenc-0.1.3 
=sys-libs/libcap-2.22-r2 
=x11-proto/xf86driproto-2.1.1-r1 
=media-libs/libshout-2.3.1-r1 
=media-libs/libdv-1.0.0-r3 
=media-sound/mpg123-1.16.0 
=media-libs/libogg-1.3.1 
=media-libs/libmimic-1.0.4-r2 
=media-libs/libvorbis-1.3.3-r1 
=media-libs/libvpx-1.2.0_pre20130625 
=x11-proto/glproto-1.4.16-r1 
=media-libs/portaudio-19_pre20111121-r1

If emerge still has troubles to resolve all conflict, try to temporarily remove all emul-linux-x86-* ebuilds first, and all conflict should go away. Enjoy Gentoo!!!