Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!






Fun with commas

  Posted by swiftcoder, 14 June 2013 · 891 views

This thread over at GameDev got me thinking, “can one assign Python-like tuples in C++?”

I don’t want to pollute the thread in For Beginners with that discussion, but the answer is yes, even without C++11 initialiser lists:

#include <iostream>

struct A {
    A &operator = (int i) {
        std::cout << "A = " << i << std::flush;

        return *this;
    }

    A &operator , (int i) {
        std::cout << ", " << i << std::flush;

        return *this;
    }
};



int main() {

    A a;

    a = 10, 20, 30;

    std::cout << std::endl;
}

Should you ever do this? Probably not. Though I’m guessing one of Boost’s container libraries is doing exactly this.

(Source)




November 2014 »

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
30      
PARTNERS