mercredi 2 mars 2022

read values of reference direct by std::pair

can someone tell me how to access the individual values directly? To really use the referent of out and not store in the temporary variable PosTextfield and val between.

#include <iostream>
#include <utility>
#include <string>
#include <cstdint>
#include <array>

using Cursor_matrix = std::array<std::array<uint16_t,2>, 1>;

void foo(const std::pair<Cursor_matrix,std::string> &out)
{
  Cursor_matrix PosTextfield;
  PosTextfield = std::get<0>(out);

  std::string val = std::get<1>(out);

  std::cout << PosTextfield[0][0] << PosTextfield[0][1] << val << "\n";
}

int main()
{
    Cursor_matrix pos;
    pos[0][0] = 1;
    pos[0][1] = 2;

    std::string str = "hello";

    std::pair<Cursor_matrix, std::string> pos_text;

    pos_text = std::make_pair(pos, str);

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire