Sign in to follow this  
  • entries
    94
  • comments
    127
  • views
    82930

Washu on aggregate types

Sign in to follow this  
Seriema

116 views

I wrote this all by myself! I researched for a week and did alot of coding to try this all out

"how can i add an element into vector" simple just do: vector v;
v += 1,2,3,4,5,6,7,8,9;
...
* snk_kid|Sugoi runs for the hills
snk_kid|Sugoi, that's cute... but isn't that part of Boost?
* snk_kid|Sugoi is still runing
no, that's just a simple example of overloading the operator += and the , operator
* Seriema runs in the opposite direction of snk_kid|Sugoi, just to prove that the earth isn't flat
I _will_ catch you snk_kid|Sugoi!
* Washu watches both of them run off the edge of the world
Washu, Boost has that though. can't remember the name though... Assignment or something
Seriema: stupid idea
gratuitous overloading of operators should result in beheadings.
Seriema- it has it, but at least it doesn't impose it on you by default.
* Fruny shudders.
* snk_kid|Sugoi imposes it
Washu, hmm why? It looks pretty darn convinient. Bjarne is even hoping for something similar (initalizer lists something for constructors)
...
initializer lists for constructors is one thing
those are already in the language, and fairly understandable
std::vector blah = {1, 2, 3, 4, 5};
that just makes sense.
ctor() : here(0) {}
we already accept that behavior for other things, like plain old structs.
Aggregate types, I should say
structs?.. I thought it only worked for POD arrays :/
struct Blah { int I; }; Blah b = {1};
* Seriema goes :O
lol
struct Blah { int I; char c; double d;}; Blah b = {1, 'a', 2.03345};
omfg :D I seriously haven't seen that!
Blah b[] = {{1, 'a', 2.324}, {3, 'b', 5.3231}};
omgomgomgomg
back in days when Washu played with WINCLASSEX
but it doesn't work for classes?..
snk_kid|Sugoi: long before that.
lol
Seriema: it doesn't work for non aggregate types
Seriema: aka, only POD types and POD arrays
and aggregate type is like someone grabbing your balls its so tight in definition
and primitive types
and primitive arrays
Washu, so it would work for classes too instead of struct, if it only holds POD/primitives ?
class Blah { public: int a; char c; double d; };
* Seriema drools
but it cannot have protected/private data
it cannot have constructors
it cannot have destructors
it cannot have a non-trivial assignment operator
it cannot have a copy constructor
and it's compiletime only.
what about pointers to objects? like struct Bla { Banana* b; }; ?
it cannot have a base class
it cannot have any virtual methods
* Seriema thinks that this would be an awesome journal post
and yes, it can have pointers
it can?! :D
aggregate types can
POD types cannot.
omgosh! then you could do lookuptables easily :D
initializers? don't think its worth journal entry unless you mean something else
aggregate initializers aren't obscure or anything.
* snk_kid|Sugoi initializes himself
* uavfun pushes Seriema back under his rock
also
What do you think, should Seriema do an entry on aggregate types?
Sure, why not, i need a good laugh...
* Washu chuckles
also, Seriema
struct {int a; char* c; int b; };
struct Blah {int a; char* c; int b; }; Blah b = { 1, "hello"};
will result in b being default constructed
which will result in b being 0
:O
(integral and floating point types default construct to 0)
oh yeah, this one is always fun
struct A { int a; operator int() { return 2; } }; struct B { A a1, a2, int z; };
A a; B b = {3, a, a};
guess what that results in Seriema?
* Seriema just stares at Washu
Seriema: you could guess
Seriema: that's the same as: B b = {{3}, {3}, 2};
which will do: b.a1.a = 3; b.a2.a = 3; b.z = 2
double matrix3x3[3][3] = { {1, 2, 3}, {1, 2, 3}, {1, 2, 3} };
double matrix3x3[3][3] = {1, 2, 3, 1, 2, 3, 1, 2, 3};
same thing, one is a lot easier to read though, Seriema
Sign in to follow this  


3 Comments


Recommended Comments

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