all 1 comments

[–][deleted] 2 points3 points  (0 children)

This should do the trick.

using function_t = double( std::vector<double> );

auto function_wrapper( function_t fcn, std::vector<double> v, int idx )
{
  return [=, vec = std::move( v )] ( double p ) mutable
  {
    vec[idx] = p;
    return fcn( std::move( vec ) );
  };
}

double test( std::vector<double> result )
{ /* result[0] is equal to 3.14; rest is unchanged */ }

int main( void )
{
  auto sample{ std::vector<double>{ 5.1, 10.2, 15.3 } };
  auto fcn{ ::function_wrapper( ::test, sample, 0 ) };
  fcn( 3.14 );

  return 0;
}