Created
September 3, 2016 14:39
-
-
Save syohex/53ba170c0d621299d727ce4f5819b8bb to your computer and use it in GitHub Desktop.
Sample code of std::tuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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