C++ —Return multiple values of different types

we usually use functions that return one or no return value.
More than one different type of return value was recently returned on a project. You can use vector to return multiple parameters of the same type. If you can use the C++11 standard, you can use my method below
(1)import the header file.

#include <tuple>
using namespace std;

(2)defined function,you can refer to the following code:

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> Table_Detection(Mat srcImage,double firstblackline_rows_ratio_thresh,bool isHorizonLine,double left_right_cols_ratio_thresh,double up_down_rows_ratio_thresh,Mat srcImageBin);

(3)function,you can refer to the following code:The type returned should be the same as the defined type.

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> Table_Detection(Mat srcImage,double firstblackline_rows_ratio_thresh,bool isHorizonLine,double left_right_cols_ratio_thresh,double up_down_rows_ratio_thresh,Mat srcImageBin)
{
;
return std::make_tuple(CUT_Table,table_new,Page_Info,isHorizonLine,table_new_cut,istablerecognition,Integrity_Check_Bottom,Integrity_Check_Top,Bottom_Integrity,Top_Integrity,tablesize);
}

(4)Now,you can call the return value. you can refer to the following code:Define a variable to receive the return parameter,the following code defines is the same as the define function.

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> data;

You also can use the auto to define. Auto is an adaptive variable in the C++11 standard.

auto data;

You can use the get method to get the data. you can refer to the following code. The code of the get<0>data actually get is CUT_Table.

std::get<0>(data);
std::get<1>(data);
std::get<2>(data);

I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.


Read More: