Announcement

Collapse
No announcement yet.

GCC 10's C++20 "Spaceship Operator" Support Appears To Be In Good Shape

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    it looks like "a<=>b" would return something like "a-b" for arithmetic-capable types, and just the sign corresponding to that operation if the types are comparable but not substractible
    it doesn't return a-b because that would fail on -1<=>1u. it returns value which can be compared to 0. its main strength is it will be autogenerated by compiler and it is much more performant than traditional approach for providing comparisons for complex types. if you have struct with two strings { string a; string b; } and want to compare it naturally, you first check if l.a==r.a, then return l.b<r.b, else return l.a<r.a. notice 2 comparisons of a. and repeat it many times for complex hierarchical types. and you don't have to use spaceship, you can(and often should) continue using standard comparisons, they will call spaceship for you
    Originally posted by [email protected] View Post
    I was not familiar with this operator.
    c++20 is packed with nice things, i'm sure you can find others you aren't familiar with
    Last edited by pal666; 06 December 2019, 09:29 PM.

    Comment


    • #22
      Originally posted by kpedersen View Post
      Correct? Hell no. Much better, we have magical compilers that allow us to inline a certain DSL for parallel processing (almost like you would do with inline assembly).
      lol, now whole world has to stop and wait for you? mainline your shit, or replace it with library

      Comment


      • #23
        Originally posted by arQon View Post
        There's always one guy who feels compelled to use whatever the latest retarded gimmick added to the language is
        there's always one guy who is unable to learn and calls all things he is too dumb to understand "gimmicks"
        Last edited by pal666; 06 December 2019, 09:34 PM.

        Comment


        • #24
          Originally posted by wizard69 View Post
          Sadly that article doesn’t clear up the point of <=> for me.
          try this one https://en.wikipedia.org/wiki/Three-way_comparison
          Originally posted by wizard69 View Post
          Maybe it is due to trying to read the article on a cell phone but I’m left with the impression that <=> offers little for the programming community. It will be interesting to see what full time C++ programmers think of the feature. Maybe my opinion will change but I would much prefer explicit definitions for each comparison possibility.
          i already gave example few posts back. it is indispensable for anyone who implemented comparisons for complex types. it makes c++ both faster and easier to use, it's like jackpot
          excerpt from proposal:

          (1) Follows all existing practice(‘the best parts’):
          The majority of existing practice for three-way comparison returns a signed integer:
          C strcmp, memcmp, qsort
          C# IComparable.CompareTo(since 1.1),Comparison<T>(since2.0)
          Java Comparable.compareTo(since J2SE1.2)
          Groovy <=>(delegates to compareTo)
          OCaml compare
          Perl <=>
          PHP <=>(since PHP 7)
          Python cmp
          Ruby <=>
          Of the major languages, only Haskell returns a type (an enumeration). This proposal does both: Like Haskell it leverages the type system by returning a type (and, more than Haskell, uses that type to distinguish the comparison category), and like the vast majority of existing practice it returns a value that can be compared against 0(as the embodiment of the mapping to the two-way comparisons).
          btw, it is easy to see that as you'd expect from the most powerful language, c++ gets the most powerful operator spaceship
          Last edited by pal666; 06 December 2019, 09:26 PM.

          Comment


          • #25
            also jokes about operator spelling are looking a little stupid when you know that c++ just chose the most used spelling for 3-way comparison among programming languages

            Comment


            • #26
              Originally posted by wizard69 View Post

              Sadly that article doesn’t clear up the point of &lt;=&gt; for me. Maybe it is due to trying to read the article on a cell phone but I’m left with the impression that &lt;=&gt; offers little for the programming community. It will be interesting to see what full time C++ programmers think of the feature. Maybe my opinion will change but I would much prefer explicit definitions for each comparison possibility.
              Basically it allows for the compiler to implement correct default comparison operators. That's it as far as it's usefulness to normal programmers goes. As far as I can tell unless you're implementing some peculiar container or sorting algorithm that has to consider all 3 states for equality for the nodes, and thus as an optimization you can turn turn two object comparisons into one object comparison and two integer comparisons there's no reason that the starship operator should ever show up in caller code.

              Comment


              • #27
                Originally posted by archibald View Post
                In case anyone is not aware of what the spaceship operator does, here is a blog post that explains it: https://blog.tartanllama.xyz/spaceship-operator.
                Thanks!

                Comment


                • #28
                  Originally posted by tildearrow View Post
                  What's next? Fish Operator (><>)? Shrug Operator (¯\_(ツ)_/¯)?

                  I have an idea but I don't want to say it...
                  The "Self-modifying code repair" operator: █▬▬ ◟(`ﮧ´ ◟ )

                  Comment


                  • #29
                    Originally posted by CommunityMember View Post
                    In C++23, a new operator @('_')@ has been proposed to facilitate monkey patching.
                    I thought this is the Princess Leia Operator

                    Comment


                    • #30
                      Originally posted by JustRob View Post

                      The "Self-modifying code repair" operator: █▬▬ ◟(`ﮧ´ ◟ )
                      I'm not sure this one would be correct in C++, given the restricted character set of the lexer

                      Comment

                      Working...
                      X