Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

pair looks like this:

std::vector<std::pair<uint64 /*id*/, std::string /*message*/>

And if I want 3 variables in vector? Can I use pair or what?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
623 views
Welcome To Ask or Share your Answers For Others

1 Answer

In C++ sometimes I find quite useful to define trivial all-public data-only classes like

struct Event {
    int id = 0;
    std::string msg = "";
    double time = 0.;
};

Surely a bit of typing, but IMO way better than having to use e.second or std::get<1>(e) instead of e.msg everywhere in the code.

Writing is done once, reading many times. Saving writing time at the expense of increasing reading/understanding time is a Very Bad Idea.

The drawback of this approach is that you cannot access the n-th member of the structure in metaprograms, but C++ metaprogramming is terribly weak anyway for a lot of other reasons so if you really need to have non-trivial metacode I'd suggest moving out of C++ and using an external C++ code generator written in a decent language instead of template tricks and hacks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...