| 12 | #include <boost/variant.hpp> |
| 13 | |
| 14 | auto get_student(int id) |
| 15 | { |
| 16 | if (id == 0) |
| 17 | return std::make_tuple(3.8, 'A', "张三"); |
| 18 | if (id == 1) |
| 19 | return std::make_tuple(2.9, 'C', "李四"); |
| 20 | if (id == 2) |
| 21 | return std::make_tuple(1.7, 'D', "王五"); |
| 22 | // 返回类型被推断为 std::tuple<double, char, std::string> |
| 23 | return std::make_tuple(0.0, 'D', "null"); |
| 24 | } |
| 25 | |
| 26 | template <size_t n, typename... T> |
| 27 | boost::variant<T...> _tuple_index(size_t i, const std::tuple<T...>& tpl) { |