Allegro5 CMake template

This is a minimal CMake template for use with allegro5.

cmake_minimum_required(VERSION 2.8)

project(MyProject)

set(SOURCES_CPP
  main.cpp
# Add files here
)

set(LIBS
  allegro
# Add libraries here 
)

add_executable(MyProject ${SOURCES_CPP})

target_link_libraries(MyProject ${LIBS})

install(TARGETS MyProject DESTINATION bin)

std::initializer_list

I was watching one of Bisqwit’s awesome videos and saw a line of code in a for loop I have never seen before. It looked something like this:

for(unsigned n: { 0xF999F,0x26227,0xF1F8F,0xF1244,
                  0xF9F9F,0xF9F1F,0xF9F99,0xF8F88 })

I wondered what type the list would be so I tried to compile this with clang and get the ast dumped but instead I got the following error:

file.cpp:5:19: error: cannot deduce type of initializer 
list because std::initializer_list was
 not found; include <initializer_list>

Aha, so we know this is an initializer_list. According to cppreference.com: “An object of type std::initializer_list<T> is a lightweight proxy object that provides access to an array of objects of type const T”. When I include <initializer_list> the code compiles. Altough the motivational uses for initializer_list are quite different than to be used as temporaries in for loops it is still a nice litte hack.