Function call inlining

Matwey V. Kornilov matwey.kornilov@gmail.com
Thu Aug 27 15:34:00 GMT 2015


Hello,

Please consider the following code from the SO:
http://stackoverflow.com/a/32237033/1879547

template<class Ret, class T, class Func, int... Is>
auto apply(T&& p, int index, Func func, seq<Is...>) -> Ret
{
     using FT = Ret(T&&, Func);
     static constexpr FT* arr[] = { &apply_one<Ret, Is, T&&, Func>... };
     return arr[index](std::forward<T>(p), func);
}

I use gcc-4.8.2 and see that arr[index](std::forward<T>(p), func) call
is not inlined.
The question here is the following. All function pointers are known at
compile time. So, why don't expand this code into analogous to the
following?

switch(index) {
	case 0:
		// inline arr[0]
	break;
	case 1:
		// inline arr[1]
	// etc...
}



More information about the Gcc-help mailing list