I am having a mental block with this LINQ expression and cannot seem to figure out how I need to convert it to C++.

(var item in inTables.SelectMany(table => table.Items))

This code applies to the following piece of code

foreach (var item in inTables.SelectMany(table => table.Items))
            {
                Trace.Assert(oldDrs.Position == item.Start);
                item.Data = reader.ReadBytes((int)item.Size);
            }

So far I have the following, but I know its not right.

for (unsigned long j = 0; j < tableCount; j++)
		inFileDrs.read(inTables[j].Items, int(inTables[j].Items.at(0).Size));

I used the for () method instead of for each because it didn't seem to be working

I did also try the for each though, figuring it maybe easier to work with since this uses a LINQ expression.

for each (auto item in inTables->Items)
		inFileDrs.read(item.Data, int(item.Size));

The main question is how do i take the SelectMany function and implement it? I understand that it takes the vector pieces that are split up and merges them all together into one continuous stream or something of the sort.

Here are my classes, may help clear things up.

class DrsItem
    {
		public:
			 long unsigned int Id;
			 long unsigned int Start;
			 long unsigned int Size;
			 std::vector<char> Data;
			 DrsItem() {Id = Start = Size = 0;}
			 DrsItem & operator=(const DrsItem & drs)
			 {
				 if (this == &drs)
					 return *this;
				 Id = drs.Id;
				 Start = drs.Start;
				 Size = drs.Size;
				 Data = drs.Data;
				 return *this;
			 }
			 DrsItem(const DrsItem & drs)
			 {
				 Id = drs.Id;
				 Start = drs.Start;
				 Size = drs.Size;
				 Data = drs.Data;
			 }
    };

    class DrsTable
    {
		public:
			 long unsigned int Type;
			 long unsigned int Start;
			 std::vector<DrsItem> Items;
			 DrsTable(long unsigned int tp, long unsigned int st, std::vector<DrsItem> itm)
			 {
					Start = st;
					Type = tp;
					Items = itm;
			 }
			 DrsTable() {Type = 0; Start = 0;}
			 DrsTable & operator=(DrsTable & drs)
			 {
				 if (this == &drs)
					return *this;
				 Start = drs.Start;
				 Type = drs.Type;
				 Items = drs.Items;
				 return *this;
			 }
			 DrsTable(const DrsTable & drs)
			 {
				 Start = drs.Start;
				 Type = drs.Type;
				 Items = drs.Items;
			 }
    };

Any help is appreciated, I know i am close to a solution, i just need it to click.

void Test()
{
for each (DsrItem ^item in inTables::SelectMany(Method1));
 {
  Trace::Assert(oldDrs->Position == item->Start);
  item->Data = reader::ReadBytes(safe_cast<int>(item->Size));
}
}

private:
void Method1(Object ^table)
{
	....
}
This article has been dead for over six months. Start a new discussion instead.