Replace iwi accessor macros with static inline functions

This removes a gcc-ism and provides better error messages when they are
misused.
Work around VC2010 lack of range-based for support

Range-based for is new in VC2012.