Time  Nick       Message
08:42 ANAND      Hi. Is there a way to compare to ItemStacks in C++?
08:42 ANAND      I could do stack1.serialize() == stack2.serialize(), but I was wondering if there's a more straightforward way to do this.
08:46 nerzhul    you must implemented == operator
08:51 ANAND      Will do
08:51 ANAND      What properties should it compare?
08:52 ANAND      I can think of name, count, and meta
08:52 ANAND      Anything else?
08:53 ANAND      Oh yeah, wear
08:55 ANAND      Why is ItemStack a struct instead of a class, btw?
10:02 nerzhul    attribtes are public ?
10:18 ANAND      Yes, but why?
11:02 nerzhul    historical and not refactored if needed ?
11:04 sfan5      ANAND: https://github.com/minetest/minetest/blob/master/src/inventory.cpp#L515-L516
11:04 sfan5      this is what it should compare
13:39 ANAND      sfan5: Thanks
13:39 ANAND      It compares meta directly?
13:40 ANAND      I thought only the serialized versions can be compared
13:44 rubenwardy that really should be in an operator==
13:45 rubenwardy an operator== will be inlined anyway
13:57 ANAND      rubenwardy: That's what I'm in the process of implementing
14:03 ANAND      Wha... operators == and != have been defined for comparing ItemStacks in around 15 files
14:05 rubenwardy lool
14:13 ANAND      And multiple definitions warnings pop up for each file that defines the operator, since the header has declared it's own version now
14:13 ANAND      https://gist.github.com/ClobberXD/b87cd0b41baa4220747f699c1cb00939
14:13 ANAND      15 is an understatement
14:13 ANAND      That's probably around 30
14:13 rubenwardy I think you've defined it wrong
14:13 rubenwardy those files all include the ItemStack file
14:14 ANAND      exactly, but they've also declared and defined their own versions of the operators
14:14 sfan5      no
14:14 sfan5      you forgot to make the method inline
14:14 rubenwardy or as part of the class
14:14 rubenwardy if you don't define a method as inline, extern, or static in a header then you will get multiple redefinitions
14:15 rubenwardy *global method
14:15 rubenwardy in this case, I'd suggest moving into the class like
14:15 ANAND      Wait... The errors are only for != operator, which I've defined in the header itself, using !(s1 == s2)
14:15 rubenwardy bool operator==(const ItemStack &other) const {
14:15 rubenwardy basically, #include is a copy and paste of another file
14:15 ANAND      Alright
14:15 ANAND      Yea
14:16 rubenwardy to the compile, it's as if you have that code directly in the C++ file
14:16 rubenwardy and so each cpp file has a definition of that operator
14:16 ANAND      :facepalm:
14:17 ANAND      Should it be defined inline or in the .cpp file if it's a member of the class?
14:18 rubenwardy as a member of the class
14:18 rubenwardy bool operator==(const ItemStack &other) const {
14:18 ANAND      Yes, but in .h within class decl. or in the .cpp file?
14:18 rubenwardy .h
14:19 ANAND      Okie
14:19 rubenwardy the .h, because the definition is trivial and it allows inlining
14:22 ANAND      Understood, thanks :)