Skip to content

Instantly share code, notes, and snippets.

@shaomeng
Created March 21, 2020 21:33
Show Gist options
  • Select an option

  • Save shaomeng/d3749e20588e76d3c406b916446652f2 to your computer and use it in GitHub Desktop.

Select an option

Save shaomeng/d3749e20588e76d3c406b916446652f2 to your computer and use it in GitHub Desktop.
pass by reference
#include <iostream>
#include <memory>
using buffer_type = std::unique_ptr<float[]>;
template< typename T >
void print_2nd_val( T ptr )
{
std::cout << ptr[1] << std::endl;
}
template void print_2nd_val( const buffer_type& );
int main()
{
int N = 10;
buffer_type buf = std::make_unique< float[] >( N );
for( int i = 0; i < N; i++ )
buf[i] = float(i);
const buffer_type& ref = buf;
print_2nd_val( ref );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment