• Advertisement
  • entries
    14
  • comments
    10
  • views
    20019

Fun with commas

Sign in to follow this  

1621 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 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)
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement