Home > Back-end >  Group of structured binding errors, pertains to neural networking
Group of structured binding errors, pertains to neural networking

Time:05-15

so i downloaded a library that hasnt been in use in years, for Neural Evolutionary Augmenting Topologies. Basically, a neural network that evolves. It came with many, MANY errors out of the box (somewhere around 20-30) and i managed to fix them all, except for these:

Error C3694 a structured binding declaration can contain no specifiers other than 'static', 'thread_local', 'auto', and cv-qualifiers

Error (active) E2828 type "float" has no components to bind to

Error (active) E0413 no suitable conversion function from "const std::tuple<float, float, float>" to "float" exists //this is dataset

Error (active) E2825 invalid specifier for structured binding declaration

this is the code where the errors are:


const int x1 = 1;
const int x2 = 2;
const int y = 1;

static constexpr int NumInput = 2;
static constexpr int NumOutput = 1;
static constexpr bool Bias = true;
static constexpr float ThresholdFitness = 0.80f;
static constexpr std::size_t PopulationSize = 100;
using ParamConfig = EvolutionNet::DefaultParamConfig;
using EvolutionNetT = EvolutionNet::EvolutionNet<NumInput, NumOutput, Bias, ParamConfig>;
using Network = EvolutionNetT::NetworkT;
using FitnessScore = EvolutionNet::FitnessScore;



for (float&& [x1, x2, y] : dataset) { // const auto, where all the errors are
                network->setInputValue(0, x1);
                network->setInputValue(1, x2);

                network->feedForward<ParamConfig>();

                const float output = network->getOutputValue(0);
                assert(output >= 0.f && output <= 1.f);

                score  = 1.f - (std::abs(output - y));
            }

i dont know anything about structured binding, im just trying to be able to use some Neural Networking for other projects. This thing isn't the best documented, but i believe that this is only meant to be a for each loop, unless structured binding has something to do with that. How would one fix these errors? thank you.

CodePudding user response:

As the error message says only the auto type specifier (and cv-qualifiers) is allowed in a structured binding, so replace float&& with auto&&.

If you are uncomfortable with this syntax, you don't need to use it though. It is purely syntactical sugar. You can access the values of the individual elements of a std::tuple with std::get, e.g.:

for(auto entry : dataset) {
    auto x1 = std::get<0>(entry);
    auto x2 = std::get<1>(entry);
    auto y = std::get<2>(entry);
    //...
}

Or instead of auto you can write out the types if you like to. If you want references to the elements in the tuple instead of just their values, add &&/&/const where appropriate.

  • Related