CppCon 2018: Simon Brand “How to Write Well-Behaved Value Wrappers”

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

ความคิดเห็น • 13

  • @botetescribavicentej.2326
    @botetescribavicentej.2326 5 ปีที่แล้ว +11

    Another title for the talk would be : How to know if a language is simple enough?
    I would like to see more things like those we will have in C++20 to make possible to implement simple things simpler.
    Glad to see that sometimes sound simple features accidentally solve problems that these features where not designed for.
    Excellent talk.

  • @nnevatie
    @nnevatie 5 ปีที่แล้ว +8

    Spaceship operator is nice, but I think we'll need a Mothership operator, that also generates all the member-wise arithmetic operators...

    • @davidledger5941
      @davidledger5941 5 ปีที่แล้ว

      Hmm
      auto & operator + - (...) ??
      auto & operator * / (...) ??

    • @nnevatie
      @nnevatie 5 ปีที่แล้ว +2

      @@davidledger5941 Yeah, exactly something like that. I would go even beyond, allowing multiple operators to be default in on go, such as:
      auto operator+-*/(const auto& t) const = default; // Motherships addition, subtraction, multiply and division operators in one go
      Essentially, the operators generated would do the member-wise operations internally. For primitive type-wrappers this would be ideal - for wrapped user types one would need to cascade the same behavior for the entire depth of the tree.

    • @davidledger5941
      @davidledger5941 5 ปีที่แล้ว

      ​@@nnevatie
      Yes, why not allow concatenation of operators like that, boolean too ||, &&. We need to submit proposals before December 21st, 2018...
      That could be much effort...
      Automatic operator generation needs to be a thing. Even if it was just allowing = default on all operators separately...

    • @mapron1
      @mapron1 5 ปีที่แล้ว +1

      I don't think automatic generation of / operator will be handy in wide hanful of cases. What does autogeneration do? divide each member ? suppose you writing your own complex number, it just bring invalid logic. I don't think perfect general algorithm for such operation could be privided.

    • @mapron1
      @mapron1 5 ปีที่แล้ว

      I think Metaclasses solves your problem partially: you could write TrivialArithmetic metaclass, where you define * operator as "multiply each member in scalar-mult behavior", then just use that metaclass.

  • @davidledger5941
    @davidledger5941 5 ปีที่แล้ว +4

    const(bool), volatile(bool), static(bool), constexpr(bool) too please:) maybe not all of them...

  • @dennisrkb
    @dennisrkb 4 ปีที่แล้ว

    pure gold

  • @zhaoli2984
    @zhaoli2984 5 ปีที่แล้ว +1

    Coming up with minimal, consistent and unsurprising semantics for operators is hard, even for Mathematicians.