« first day (2282 days earlier)      last day (2674 days later) » 
00:00 - 12:0012:00 - 00:00

12:00 PM
@VermillionAzure Start with a simple class containing a union. Add features as needed.
 
@Brandin yeah so i don't think it's that simple
 
> Member for 2 days
@VermillionAzure You use std::aligned_union and an int to keep track of which type is active
 
The trick is to start as simple as possible.
 
@CheukKinSing why use an aligned union?
And I'm writing it right now
 
@VermillionAzure think about it
 
12:06 PM
@CheukKinSing ...I don't see a reason
 
@CheukKinSing What's wrong with an ordinary union? It already guarantees alignment.
 
Ell
@Brandin how do you use an ordinary union in generic code?
also
you can't have real stuff inside a union
 
@VermillionAzure well then you didn't think enough :)
 
@Ell Template union of course :p
 
@CheukKinSing And you're being awfully smug about this
 
12:09 PM
wow
I told you what to use
and to think about the why
and you tell me I'm smug?
 
@CheukKinSing You ignored my question.
 
fuck off
 
Ell
lol
 
meh.
sorry
 
Ell
@VermillionAzure do you know what std::aligned_union does?
 
12:10 PM
@Ell no, and I asked why we should use it over the normal one.
I don't see why an aligned union would be much more helpful unless it's just for performance
 
Ell
> Provides the member typedef type, which is a POD type of a size and alignment suitable for use as uninitialized storage for an object of any of the types listed in Types.
this is precisely your requirement, no?
 
@Ell Yes? I guess I have to learn about that as well.
@Ell Is the in-place initialization required for such a thing? Why would it not just work already as a regular union?
 
Ell
@VermillionAzure well you want to improve on regular unions somehow, right?
You are writing variant after all
you must have some reason not just to use union :P
 
@Ell All I care about is putting in and extracting types in a functional manner. I plan to extract concrete types from it
 
Ell
well there's your answer
can you do that with a union?
 
12:15 PM
@Ell So the plan, I guess, is to use a enum as the type switch and the union as the storage
 
Ell
it would be easier to use an int I think
 
:35103574
 
Ell
variant<int, string, foo, bar>
each type gets an int
 
@Ell Doesn't matter. You can inherit from a basic type. And, remember, I can't use std::variant
I'm using C++11 and refraining from using Boost right now.
 
@Ell I didn't hear the requirement that it is generic. If you have a handful of types, plain union is just fine.
 
Ell
12:17 PM
@Brandin not always
it depends on the types
 
Yeah so, I guess the first problem I'm getting is that if you're not using POD, it gets much harder
Ah.
 
12:37 PM
@VermillionAzure Why does it matter if it is a POD or not?
 
@Brandin Welp, after looking around, the designers of C++ decided that items that are not POD with multiple possible constructors and a possibly deleted default constructor can't be easily decided upon.
@Brandin So you need to provide a custom implementation for every copy/move/constructor/destructor/operator that's non-trivial
 
Is there a known number of types that you need to vary on?
 
@Brandin Yes and no.
@Brandin Currently, I just need to implement SOMETHING so I get the basic gist of things
But eventually, user-defined types will be a thing
 
Then just start simple with something that works, and add on/refactor as needed.
How about something like this:
`
class Variant
{
enum Type {V_NOTHING,V_PERSON,V_PLACE,V_THING} type;
union Obj {
Person pe;
Place pl;
Thing th;
Obj() : dummy(0) {}
int dummy;
} obj;
static void check(bool cond) {
// Customize if you want a different error-handling mechanism:
if (!cond) throw 1;
}
`
I don't know how to format code here, but maybe you get the idea.
 
@Brandin There's a button to do that
 
12:50 PM
a
b
c
class Variant
{
    enum Type {V_NOTHING,V_PERSON,V_PLACE,V_THING} type;
    union Obj {
        Person pe;
        Place pl;
        Thing th;
        Obj() : dummy(0) {}
        int dummy;
    } obj;
    static void check(bool cond) {
        // Customize if you want a different error-handling mechanism:
        if (!cond) throw 1;
    }
etc.
public:
    // Nothing:
    Variant() :type(V_NOTHING), obj(Obj()) {}

    // Person:
    Variant(const Person& pe) :type(V_PERSON) { obj.pe = pe; }
    bool is_Person() { return type == V_PERSON; }
    const Person& get_Person() const { check(type==V_PERSON); return obj.pe; }

    // Place:
    Variant(const Place& pl) :type(V_PLACE) { obj.pl = pl; }
    bool is_Place() { return type == V_PLACE; }
    const Place& get_Place() const { check(type==V_PLACE); return obj.pl; }
and so on
 
@Brandin Yes... Except... I'm having problems with the named union
Because of the rule that named unions must provide implementations with non-trivial data types in their contents, that means I'd have to manually write move/copy/assignment/default/destructor functions...
So that code ends up bloating up VERY quickly
 
If you want your variant type to copy, as in the above example, then of course every type must have a copy constructor.
 
@Brandin Of course. However... I think I'd prefer anonymous unions for now
It couples the code to the variant itself, yes, but that will do for now
 
They don't need a default constructor though. My 'Person' type has no default constructor, for example. It still goes into a Variant.
 
@Brandin What type is Person, though?
 
12:58 PM
char array
heh
 
@Brandin Welp, either way...
@Brandin This is working
 
Person, Place and Thing are three example user-defined types. I thought it would be more illustrative than A, B, C or something. They can be anything at all. In my case, my Person is 200 bytes long, my Place and Thing are each 8 bytes long. So a Variant is 204 bytes long (size of biggest member +4 for the enum).
 
@Brandin Yes, but I was wondering what type of non-trivial operators it had
But either way, this works nicely.
 
They should be able to be anything at all. You can add whatever user-defined operators you want to all of your types. As long as they are copyable.
Add more features as you need them. For example I tried to write this:
vector<Variant> vv;
vv.push_back(Person("fn","ln"));
vv.push_back(Place());
// ...

for (const auto& x : vv) {
    if (x.is_Person()) {
        cout << "It's a Person:"<< x.get_Person() <<"\n";
    } else if (x.is_Place()) {
        cout << "It's a Place!\n";
    } else if (x.is_Thing()) {
        cout << "It's a Thing!\n";
    } else {
        cout << "I don't know what it is.\n";
    }
}
But I may want to be able to use a switch in the for loop. So, add an accessor to your Variant type that you can switch on, etc.
 
Making a decent pair type is rather difficult :/
 
1:04 PM
@Brandin But you see now
Hm...
@Brandin What makes named unions so different from anonymous unions, I wonder...
Maybe it's that the named union is self-encapsulated so that its limited scope requires such overloading... But that same scope also prevents it from switching on a tag, since the union can contain only a union...
 
The only difference for anonymous unions is in the way the members are accessed. To convert my Variant from above to use anonymous union, you need only do this:
class Variant
{
    enum Type {V_NOTHING,V_PERSON,V_PLACE,V_THING} type;
    union {
        Person person;
        Place place;
        Thing thing;
        int dummy;
    };
/*...*/
/*...*/
public:
    // Nothing:
    Variant() :type(V_NOTHING), dummy(0) {}

    // Person:
    Variant(const Person& pe) :type(V_PERSON) { person = pe; }
    bool is_Person() const { return type == V_PERSON; }
    const Person& get_Person() const { check(type==V_PERSON); return person; }
/*...*/
The user code would not change. The acccessors allow that this still works:
vector<Variant> vv;
vv.push_back(Person("fn","ln"));
vv.push_back(Place());
// ...
 
@VermillionAzure look into the implementation of std::variant
 
To allow user code to use 'switch', provide an accessor that exposes a 'type'-like value. You could make type public.
 
Or boost::variant
Or a zillion other existing ones.
 
@R.MartinhoFernandes Is the std::variant better than the boost one? Because the boost one is unreadable with all the macros
 
1:14 PM
any wasn't too bad
 
@fredoverflow I've tried sleeping but I accidentally stumbled over the original article and was so enraged while reading it, I can't sleep now
2
 
So ahem
How should I return a value from a variant?
 
u w0t m8
 
@milleniumbug So.
std::variant keeps track of type and uses templated calls using std::get to create a clean interface to extract the type you want
And it throws if you try to access the wrong type
However, I have this makeshift implementation that does not do this
 
@VermillionAzure I don't think your line 24 is correct. Placement new? coliru.stacked-crooked.com/a/9b4424ed8ebfa503
 
1:26 PM
@Brandin I believe that's correct.
 
I find it amusing this guy complains about Swift and Kotlin (that they try to prevent the programmer from making mistakes), but he uses Java. The irony is stunning if you consider the goals they had in mind while designing Java.
 
The code that I saw people use is using placement new.
 
What does it mean?
 
@Brandin Who are you talking to
 
1:28 PM
@VermillionAzure I understand the line now. It is a bit confusing. But isn't it the same as writing this->str = str;? It is just a copy.
 
@Brandin no.
@Brandin So I tried doing that. It fails. Why? Because std::string isn't even initialized there yet, so it gives a segfault.
 
@Brandin that's calling the copy constructor, your calls the copy assignment operator
 
@Brandin Since the constructor is supposed to actually setup everything in the first place, we need to construct it in-place where the union is.
 
I thought copy assignment defaults to a copy constructor, if there is one.
 
...no
 
1:34 PM
@Brandin Yeah... It's just a plain operator, tbh.
@Brandin It may seem that way, but it's really all just by convention... I could very well have a assignment << operator I think and things would still work.
 
2:14 PM
lol people making assumptions in locale questions when they don't even know the OS and libc
 
2:27 PM
5 messages moved to Trash can
 
@Brandin No. Copy construction uses the copy constructor. Copy assignment does member-wise assignment by default.
 
OK. So if in my class C all of the members have sensible operator='s, I can count on the default C::operator= to just copy all of the members using each member's operator=.
 
2:50 PM
Would you see it as a privacy concern if you tried to sign up with someones email and it told you the email had already signed up?
damn i didnt realise this was for c++
 
@Brandin yes, that's the essence of Rule of Zero
if one member needs special treatment, wrap it inside a type that does provide suitable operator=s
 
@TheCodesee Is it a common e-mail address. E.g. alice@SOME_COMMON_FREE_EMAIL_DOMAIN
It is probably sloppy procedures on the part of that service. If my address is alice@here and your address is alice@there (two different legitimate addresses), you could accidentally type in my address, or I could accidentally type in yours, by a one-character typo. If there is no verification, then there is no way to verify that it is a correct address.
 
 
1 hour later…
user1804599
4:03 PM
> Inductive ascii : Set := Ascii (_ _ _ _ _ _ _ _ : bool).
 
user1804599
Good job Coq 8-bit ASCII.
 
4:26 PM
Thor's hammer fails me simply because the OP on the other post was to lazy to upvote my answer
 
Ven
4:39 PM
@sehe gave you one. It's nice
 
I love nice upvotres :)
The french pun is accidental but it can stay
 
Ven
@sehe à la tienne !
@sehe you should champion a foo::bar::{a, b, c} proposal :P
 
Hmmm?
 
I want to learn to shoot a gun and a rifle.
 
@Xeo It was fun for a couple of hours, then I crashed my rover into a cave and died :D
@wilx IDKFA
 
4:58 PM
@fredoverflow What? :)
@fredoverflow A Doom game cheat code? :)
Heh.
 
It gives you all the weapons ;)
 
Haha.
 
nwp
5:19 PM
@wilx if you used C++ for a while and still have a foot they should just give you a gun license
17
 
@nwp Hehe. :D
@nwp Well, that holds true for most of us. :))
 
"I did a lot of research regarding json parser and xml parser in boost" - that's interesting, because Boost has no JSON library, not an XML library. — sehe 9 mins ago
grrr
 
Ven
@sehe neither / nor?
 
@Ven Indeed. I dumbed it down so as to risk the OP understanding me.
 
Ven
:D
 
5:23 PM
Oh. And typoed it I notice now
 
Ven
Remember: everytime you use a complex english construct, you confuse a frenchman
 
@wilx YES! That's the Property Library. You know what that does?
It deals with property trees.
 
@sehe Do I have to answer? :)
 
5:27 PM
I already did.
Every fucking man on the planet goes to boost and thinks "HEY THIS SMELLS LIKE JSON/XML, LET'S USE IT"
And then they moan because they get stuck trying to do things that Property Trees were not intended to do
It's really unfortunate.
 
@sehe You are discriminating women and those of the 70 remaining genders in that statement. Even your rants should be inclusive!
 
Start with number typed JSON nodes. Then we'll talk
All right. Time to say it. I think #Boost PropertyTree is an odd thing. It appears to be best at generating confusion and get abused a lot.
Also notice my answer at that very question :)
@wilx See, you're nowhere alone:
@sehe: I thought Property Tree supported JSON. — Christian Hackl 3 mins ago
 
@sehe :)
 
That's the prime reason this upsets me a bit. The amount of time wasted by the interwebs at large is just stupendous
Jan 18 '15 at 12:27, by sehe
@OhadM You should use what you prefer. At work I use (an improved version of) the parser you you just saw. Mostly in automated serialization code (so user friendliness is not a goal). Thing is, Boost Property tree is not a XML/JSON/Whatever library. It is a PropertyTree library (Whatever the hell that is. I admit I think Boost PropertyTree doesn't need be in Boost. It's applicability appears to be mimimal) — sehe 7 secs ago
That's only the oldest bit that comes up
t.co/lJ3X0o89rj SpaceX launch
 
5:52 PM
@sehe It is. Maybe somebody should talk to nlohmann about whether he'd be amenable to distributing his JSON library through Boost.
 
We joke about 'bromance' but such a prominent example of loving, emotional, supportive male friendship sends such a… https://twitter.com/i/web/status/819977367926013952
 
user1804599
That rocket is super phallic.
 
Ell
@Borgleader I'm rewatching this now :D
 
Its a great show, I should re-watch it some time
 
6:19 PM
Sauerkraut is awesome.
 
user1804599
Wunderlist has this killer feature where clicking a checkbox gives a sense of accomplishment.
 
user1804599
@wilx IMO it is disgusting.
 
user1804599
It's one of those "foods" that I don't eat even if other people prepared it for me.
 
@Mgetz I didn't ignore anything. Yes, it's best to check if (locale == NULL), but that's separate from anything you mentioned before. "Doesn't handle wide characters" — if fwprintf is available we assume it works. It's not defensive to point out that you're making a lot of false claims. They waste time and add noise to the page. — Potatoswatter 9 mins ago
what a fool
 
6:25 PM
I'm too lazy to handle unicode correctly, I just and all my chars with 0x7f ;)
 
oh I'm only annoyed because they made personal attacks for no reason
 
user1804599
@fredoverflow Just use Perl 6 or Rust.
 
@rightfold I can't remember if you love or hate Perl, what is you current feeling towards the language?
 
user1804599
It is meh.
 
@fredoverflow BDSM?
 
user1804599
6:28 PM
BDSM isn't meh. It's fun.
 
@fredoverflow Love!
 
6:43 PM
@CheukKinSing s5 pvp is still not over either!
 
7:05 PM
 
Ell
7:47 PM
wat
 
8:03 PM
@Ell I just typed $(x) with my $(x).
 
If VIM opens I just delete the server instance.
 
Ell
oh lol
 
Oh man. This is too great
Ik ❤ Twitter https://t.co/D7kx7N08Cf
 
user1804599
I want to make juice.
 
user1804599
By putting different fruits in a blender.
 
8:17 PM
That's old hat
 
user1804599
Albeit delicious.
 
@sehe lol, that's p/good.
@rightfold That will not be a juice but porridge.
 
It's called a smoothie
 
Ell
@wilx if he has a magic blender maybe :P
 
user1804599
@wilx without the crusts you fool
 
Ell
8:30 PM
this is quite amusing for me
pizzas have crusts, fruit has a skin or peel
 
3-gatsu no lion's second ED is pretty good
 
Ell
and porridge is made of oats :3
 
Ok ok ok... you win.
 
8:42 PM
@Ell ...or peas. Or beans. Probably at least a few other things as well. "Peas porridge hot. Peas porridge cold. Peas porridge in the pot, nine days old!"
 
Ell
@JerryCoffin Hmm
supposedly :P
No fruit though
I mean you can and should put fruit in porridge to make it tasty
 
user1804599
@Ell acorn porridge is great
 
https://t.co/GR6IJJiFE8
4
 
user1804599
9:05 PM
If you like universal type inhabitants in your lang, why stop at only one? More nulls means you can write more tests.
 
@rightfold Out of curiosity, is there a benefit to having other types like NaN, undefined, etc. in a language rather than exceptions?
 
9:44 PM
@Borgleader fuck you I would if I could!
:P
 
@jaggedSpire fuck me indeed :P
 
lol
 
Ell
@Aaron3468 performance maybe
if you threw an exception every time you encountered NaN in your FPU, perhaps that wouldn't be quick enough
oh wait
do you mean other values like NaN, undefined, etc.?
 
user1804599
Not a Null
 
Ah, I forget that exceptions are quite heavy. But yeah, is there a benefit in having NaN, undefined, infinity, etc. defined as their own type? And if so, should there be a way to catch them all as a null value of some sort to simplify testing?
 
Ell
9:55 PM
ah I see
@Aaron3468 are you talking about just floating point stuff?
 
red panda video /cc @Borgleader @TonyTheLion @ThePhD @Ven @Xeo
 
10:18 PM
@Ell Not necessarily, though it tends to be a source of many variant-typed return values. Many other situations where null is traditionally used can be given different return types such as Device_busy, Not_Allocated, etc. depending on the particular language. Often null is used in situations that could alternately generate an exception, which seems to be the point made in the tweet.
 
Ell
I think generally it is good to use the type system as much as you can
there is a tradeoff of course
 
user1804599
@Ell Unfortunately, in most languages this means "so, not very much"
 
user1804599
@Aaron3468 No, the tweet is a joke mocking people who like terrible decisions like universal nulls.
 
user1804599
The kind of people who drink coffee while their home is on fire.
 
I am bored and the can that used to contain cider is empty. Life is hard.
 
user1804599
10:31 PM
@wilx Learn a new programming language!
 
@rightfold I'd rather do something awesome in the ones I know.
 
@rightfold Ah, is there another term for universal? Can't seem to use google to figure out the meaning in this context
 
@Aaron3468 A null doesn't follow normal type restrictions, such as NULL in C++, which could be assigned to either integer types or pointer types.
(of course, I'm only making an assumption that this is the sort of thing he's talking about--the phrasing he used isn't nearly universal, or anything like that, so it's impossible to be certain. Such is Twitter: nearly everything condensed down to the point that it's impossible to know what it really means.
 
11:02 PM
@wilx contribute to OpenCV
 
@Mikhail I know zilch about graphics.
 
Oh, so then NULL could be integer, pointer, vector, or object? That's a terrible idea! It's almost unequivocally better to just have Integer.NULL, Pointer.NULL, and so on. And of course, if you need a universal, then the language can include a variant type that can be any of those NULL types (though I'm not sure I see why to use it).
 
In the future we're going to have a mechanism to address objects by their memory locations, rather than by some obfuscated handle to memory
 
Ell
lol
 
user1804599
11:19 PM
public void f(Object x) { }
public void f(Object... x) { }
f(new Object[0]);
 
user1804599
@fredoverflow which is called?
 
user1804599
(lol no explicit ... at call-site)
 
@rightfold I'd say the second one
 
user1804599
@набиячлэвэли wrong!
 
11:36 PM
@Mikhail I think you are going in the wrong direction - in the future A.I. is going to take over everything, including your std::vectors
 
00:00 - 12:0012:00 - 00:00

« first day (2282 days earlier)      last day (2674 days later) »