D
@no_name1991 Ich hatte vorhin einen kurzen Schnack mit Copilot... ich glaube, du meintest das so:
#include <iostream>
#include <map>
#include <optional>
#include <tuple>
struct sbasic
{
unsigned short int length; // laenge
unsigned short int width; // breite
unsigned short int height; // hoehe
unsigned short int type; // art
unsigned long long int x; // Position
unsigned long long int y; // Position
unsigned long long int z; // Position
bool operator<(const sbasic &other) const
{
return std::tie(length, width, height, type, x, y, z) < std::tie(other.length, other.width, other.height, other.type, other.x, other.y, other.z);
}
};
// zuladung
struct spayload
{
unsigned short int type; // art
bool operator<(const spayload &other) const
{
return type < other.type;
}
};
// zuladung menge
struct spayloadamount
{
unsigned short int type[64]; // art
unsigned short int amount[64]; // menge an zuladung
};
int main(int argc, char *argv[])
{
std::map<spayload, std::map<sbasic, std::optional<spayloadamount>>> m;
m.insert(std::make_pair(spayload{1}, std::map<sbasic, std::optional<spayloadamount>>{}));
m.insert(std::make_pair(spayload{2}, std::map<sbasic, std::optional<spayloadamount>>{}));
m[spayload{1}].insert(std::make_pair(sbasic{10, 20, 30, 1, 100, 200, 300}, spayloadamount{{1, 2}, {10, 20}}));
m[spayload{1}].insert(std::make_pair(sbasic{15, 25, 35, 2, 150, 250, 350}, spayloadamount{{3, 4}, {30, 40}}));
m[spayload{2}].insert(std::make_pair(sbasic{20, 30, 40, 3, 200, 300, 400}, std::nullopt));
m[spayload{2}].insert(std::make_pair(sbasic{25, 35, 45, 4, 250, 350, 450}, std::nullopt));
for (const auto &[payload, basicMap] : m)
{
std::cout << "Payload Type: " << payload.type << std::endl;
for (const auto &[basic, payloadAmountOpt] : basicMap)
{
std::cout << " Basic: Length=" << basic.length
<< ", Width=" << basic.width
<< ", Height=" << basic.height
<< ", Type=" << basic.type
<< ", Position=(" << basic.x << ", " << basic.y << ", " << basic.z << ")"
<< std::endl;
if (payloadAmountOpt)
{
const auto &payloadAmount = *payloadAmountOpt;
std::cout << " Payload Amounts:" << std::endl;
for (size_t i = 0; i < 64; ++i)
{
if (payloadAmount.type[i] != 0)
{ // Assuming type 0 means no payload
std::cout << " Type: " << payloadAmount.type[i]
<< ", Amount: " << payloadAmount.amount[i]
<< std::endl;
}
}
}
else
{
std::cout << " No payload amount available." << std::endl;
}
}
}
return 0;
}
Also eine Map, die wieder eine Map hält - anstatt das Variant-Gedengele...