Skip to main content
fixed bad sample code
Source Link
Addy
  • 2.5k
  • 1
  • 23
  • 48

If I have a struct like:

struct Thing
{
  int x,x;
  int y,y;
  bool a,a;
  bool bb;
}

Then I can create a Thing object by doing: Thing t {1,2,true,false};. However, if I have a tuple then I am doing something like:

std::tuple<int, int, bool, bool> info = std::make_tuple(1,2,true,false);
Thing t { std::get<0>(info), std::get<1>(info).. // and so on

Is there a better way to do this?

If I have a struct like:

struct Thing
{
  int x,
  int y,
  bool a,
  bool b
}

Then I can create a Thing object by doing: Thing t {1,2,true,false};. However, if I have a tuple then I am doing something like:

std::tuple<int, int, bool, bool> info = std::make_tuple(1,2,true,false);
Thing t { std::get<0>(info), std::get<1>(info).. // and so on

Is there a better way to do this?

If I have a struct like:

struct Thing
{
  int x;
  int y;
  bool a;
  bool b;
}

Then I can create a Thing object by doing: Thing t {1,2,true,false};. However, if I have a tuple then I am doing something like:

std::tuple<int, int, bool, bool> info = std::make_tuple(1,2,true,false);
Thing t { std::get<0>(info), std::get<1>(info).. // and so on

Is there a better way to do this?

Source Link
Addy
  • 2.5k
  • 1
  • 23
  • 48

Constructor arguments from a tuple

If I have a struct like:

struct Thing
{
  int x,
  int y,
  bool a,
  bool b
}

Then I can create a Thing object by doing: Thing t {1,2,true,false};. However, if I have a tuple then I am doing something like:

std::tuple<int, int, bool, bool> info = std::make_tuple(1,2,true,false);
Thing t { std::get<0>(info), std::get<1>(info).. // and so on

Is there a better way to do this?