Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Stoopid me

Stoopid me

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marco Bertschi
    wrote on last edited by
    #1

    I just produced this Gem:

    template struct Expectation{
    T expected;
    Expectation(T e)
    : expected(e){}
    bool Expect(const T &other){
    return (other == expected);
    }
    };

    Which shall be used as

    foo firstFoo(1);
    Expectation myExpectation();
    foo anotherFoo(1);
    if(myExpectation.Expect(anotherFoo)){
    //bar
    }

    After I got a coffee (proud of the genius work I did) I returned to my desk an all of sudden I realised that I just could've written

    foo firstFoo(1);
    foo anotherFoo(1);
    if(firstFoo == anotherFoo){
    //bar
    }

    One hour left, it's definately time for me to get outta here :doh:

    You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

    N 1 Reply Last reply
    0
    • M Marco Bertschi

      I just produced this Gem:

      template struct Expectation{
      T expected;
      Expectation(T e)
      : expected(e){}
      bool Expect(const T &other){
      return (other == expected);
      }
      };

      Which shall be used as

      foo firstFoo(1);
      Expectation myExpectation();
      foo anotherFoo(1);
      if(myExpectation.Expect(anotherFoo)){
      //bar
      }

      After I got a coffee (proud of the genius work I did) I returned to my desk an all of sudden I realised that I just could've written

      foo firstFoo(1);
      foo anotherFoo(1);
      if(firstFoo == anotherFoo){
      //bar
      }

      One hour left, it's definately time for me to get outta here :doh:

      You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

      N Offline
      N Offline
      Nicholas Marty
      wrote on last edited by
      #2

      which in addition should return false as long as its a reference type and you didn't overwrite the Equals Operator ;)

      M 1 Reply Last reply
      0
      • N Nicholas Marty

        which in addition should return false as long as its a reference type and you didn't overwrite the Equals Operator ;)

        M Offline
        M Offline
        Marco Bertschi
        wrote on last edited by
        #3

        Nicholas Marty wrote:

        you didn't overwrite the Equals Operator

        I overwrote it. Well, better: I had to implement it since QObject (the base class for objects in the Qt framework) has not implemented it (means not implementing the equals operator would've led to a compiler error, anyways). Edit: QObject has also a private copy constructor, means that you have to implement a copy constructor yourself before doing something like

        foo myFoo = GetFoo(); //Assuming GetFoo returns a foo type

        You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

        F 1 Reply Last reply
        0
        • M Marco Bertschi

          Nicholas Marty wrote:

          you didn't overwrite the Equals Operator

          I overwrote it. Well, better: I had to implement it since QObject (the base class for objects in the Qt framework) has not implemented it (means not implementing the equals operator would've led to a compiler error, anyways). Edit: QObject has also a private copy constructor, means that you have to implement a copy constructor yourself before doing something like

          foo myFoo = GetFoo(); //Assuming GetFoo returns a foo type

          You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

          F Offline
          F Offline
          Freak30
          wrote on last edited by
          #4

          Assuming this is C#, shouldn't the example be like this?

          foo myFoo = new foo(GetFoo())

          At the moment you only assign the reference, not requiring a copy constructor.

          The good thing about pessimism is, that you are always either right or pleasently surprised.

          M R 3 Replies Last reply
          0
          • F Freak30

            Assuming this is C#, shouldn't the example be like this?

            foo myFoo = new foo(GetFoo())

            At the moment you only assign the reference, not requiring a copy constructor.

            The good thing about pessimism is, that you are always either right or pleasently surprised.

            M Offline
            M Offline
            Marco Bertschi
            wrote on last edited by
            #5

            Freak30 wrote:

            Assuming this is C#

            It is not. It is C++.

            Freak30 wrote:

            At the moment you only assign the reference, not requiring a copy constructor.

            The foo class is inherited from QObject, where an assignment automatically invokes the copy constructor (despite you are working with pointers, off course).

            You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

            S 1 Reply Last reply
            0
            • M Marco Bertschi

              Freak30 wrote:

              Assuming this is C#

              It is not. It is C++.

              Freak30 wrote:

              At the moment you only assign the reference, not requiring a copy constructor.

              The foo class is inherited from QObject, where an assignment automatically invokes the copy constructor (despite you are working with pointers, off course).

              You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

              S Offline
              S Offline
              Sentenryu
              wrote on last edited by
              #6

              Don't all C++ object assignments invoke the copy constructor?

              I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

              M 1 Reply Last reply
              0
              • S Sentenryu

                Don't all C++ object assignments invoke the copy constructor?

                I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

                M Offline
                M Offline
                Marco Bertschi
                wrote on last edited by
                #7

                I suppose they do - Except for some special cases (private copy constructor, as seen in the QObject class).

                You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."

                1 Reply Last reply
                0
                • F Freak30

                  Assuming this is C#, shouldn't the example be like this?

                  foo myFoo = new foo(GetFoo())

                  At the moment you only assign the reference, not requiring a copy constructor.

                  The good thing about pessimism is, that you are always either right or pleasently surprised.

                  R Offline
                  R Offline
                  Rob Grainger
                  wrote on last edited by
                  #8

                  Wrong asssumption, the

                  template <class T> struct Expectation

                  bit gives it away.

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                  1 Reply Last reply
                  0
                  • F Freak30

                    Assuming this is C#, shouldn't the example be like this?

                    foo myFoo = new foo(GetFoo())

                    At the moment you only assign the reference, not requiring a copy constructor.

                    The good thing about pessimism is, that you are always either right or pleasently surprised.

                    R Offline
                    R Offline
                    Rob Grainger
                    wrote on last edited by
                    #9

                    Why on earth would you assume it is C#. Does "template <class T> struct Expectation ... " make any sense in C#?

                    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups