I recently decided to unclutter a header file which had a lot of definitions like so:
// api.h
template< typename T>
inline void func( T param )
{
// stuff here
}
so I thought of turning it into:
// api.h
#include "api_details.h"
template< typename T>
inline void func( T param )
{
return details::func( param );
}
// api_details.h
namespace details {
template< typename T>
inline void func( T param )
{
// stuff here
}
}
hoping that inline
wouldn't add a cost to the extra copy I'm performing.
although the answers in 'C++ do inline functions prevent copying?' seem to imply that no copying takes place, this question arises:
if inlining doesn't copy the function parameters, then wouldn't the following behave badly?
inline void change_value( int i ) {
i++;
}
...
int x=5;
change_value(x);
assert(x==5);
is it just the optimizer that decides where to copy or not, or does the standard say anything about that?