How do I terminate an "auto" type function with a structure return type during execution?
I want to escape the auto function 'Func' (not the entire program) when some condition is satisfied as follows:
#include "stdafx.h"
#include <vector>
#include <tchar.h>
#include <iostream>
using namespace std;
auto Func(int B, vector<int> A) {
for (int a = 0; a < B; a++)
{
A.push_back(a);
if (a == 2)
{
cout << " Terminate Func! " << endl;
// return; I want to terminate 'Func' at this point
}
}
struct result { vector <int> A; int B; };
return result{ A, B };
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> A;
int B = 5;
auto result = Func(B, A);
A = result.A;
B = result.B;
for (int a = 0; a < A.size(); a++)
{
cout << A[a] << endl;
}
}
I don't want to use "exit()" because I just want to terminate a function not the program.