Hi Robert,
I do not know the specifics of Boost.Range, but I believe what you are trying to do here is in fact undefined behaviour for initializer_lists. Reported defect DR1290 (see reference 1) explains the idea behind the temporary storage of an initializer_list in more detail. Some compilers (notably Clang) 'exploit' this undefined behaviour in order to further optimize the usage of initializer_lists. On the other hand, using it to initialize a vector and using this vector (which is more strict on the lifetime of its storage) is fully defined and therefore works as expected.
As a result, Boost.Range, which does not necessarily require copy semantics and therefore uses a reference to the collection
(see reference 2), can only do the right thing while the storage behind the object still exists.
Kindest Regards,
Bart
References: