yo/advancedtemplates/examples/tuples.cc
raw| 1 | #include <iostream> |
| 2 | #include <tuple> |
| 3 | #include <string> |
| 4 | using namespace std; |
| 5 | |
| 6 | int main() |
| 7 | { |
| 8 | using tuple_idsc = std::tuple<int, double &, std::string, char const *> ; |
| 9 | |
| 10 | double pi = 3.14; |
| 11 | tuple_idsc idsc(59, pi, "hello", "fixed"); |
| 12 | // tuple_idsc empty; // cannot do this: no reference to double |
| 13 | |
| 14 | cout << tuple_size<tuple_idsc>::value << '\n'; |
| 15 | tuple_element<2, tuple_idsc>::type text("hi"); |
| 16 | |
| 17 | // access a field: |
| 18 | get<2>(idsc) = "hello world"; |
| 19 | } |