Is there any other way to receive a reference to an array from function returning except using a pointer?
Here is my code.
int ia[] = {1, 2, 3};
decl
Some alternatives I think are superior in C++14 onwards:
auto and array reference trailing return type:
template
auto array_ref_test(T(&array)[N]) -> T(&)[N]
{
return array;
}
decltype(auto):
template
decltype(auto) array_ref_test(T(&array)[N])
{
return array;
}
Example usage:
int array_ref_ [] = { 1, 2, 3, 4, 5 };
decltype(auto) array_ref_result = array_ref_test(array_ref_); //'decltype(auto)' preserves reference unlike 'auto'
std::cout << std::size(array_ref_result);