mardi 17 décembre 2019

Create array from member variable from containing array [closed]

I'm sure this has already been asked, but I couldn't find the right terms to express myself.

I am trying to interface with a function that requires an array of fixed size. There are many different members with corresponding functions that require this form (not shown here for simplicity). I have made an attempt of making an accessor "function". I've put '?' where I'm really unsure.

int timeSteps = 1000;
struct B { bool a=true; }
struct Foo {
   std::vector<int> bar(nPhases);
   std::vector<B> baz(nPhases);
}

int sillyFunc(std::array<int, 4> manyInts){int computedValue; /*...*/ return computedValue;}

//In reality this is instantiated elsewhere and I have a reference to it
std::array<Foo, 4> positionFoos = {Foo(), Foo(), Foo(), Foo()};

//My attempt to try to 'switch' the order so I can access the members
template <typename T> constexpr   
std::array<Foo, X /*?*/ > &&  accessThings(std::array<Foo, X /*?*/ > &foos) 
    {
      std::array<T, foos.size()> ret
          for (int i = 0; i < X; ++i)
              ret[i] = EEs[i].T;
      return std::move(ret);
    }

std:vector<int> calculatedOutputs(timeSteps);
for (auto i=0; i < timeSteps; ++i) {
  calculatedOutputs[timeSteps] = sillyFunc(accessThings<bar, 4>(positionFoos)[i]; //?
}

What's the canonical (if there is such a way of achieving this? Lambdas? template voodoo?

Aucun commentaire:

Enregistrer un commentaire