Skip to content

Instantly share code, notes, and snippets.

@syohex
Created September 3, 2016 14:39
Show Gist options
  • Save syohex/53ba170c0d621299d727ce4f5819b8bb to your computer and use it in GitHub Desktop.
Save syohex/53ba170c0d621299d727ce4f5819b8bb to your computer and use it in GitHub Desktop.
Sample code of std::tuple
#include <iostream>
#include <tuple>
#include <string>
std::tuple<std::string, int>
func(int i)
{
if (i == 0) {
return std::tuple<std::string, int>(std::string("hello world"), 0);
} else {
return std::tuple<std::string, int>(std::string(""), -1);
}
}
int main(void)
{
std::string ret;
int err;
std::tie(ret, err) = func(1);
if (err != 0) {
std::cout << "ERROR" << std::endl;
return -1;
}
std::cout << "SUCCESS:" << ret << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment