« first day (1134 days earlier)      last day (1710 days later) » 

12:54 AM
well, simple question then, please help with the following - i have a class with the copy constructor like Class(const Class &c)
but this does not work for arrays, i.e. for Class ca[1]; Class c; ca[0]=c; copy constructor not called probably because arrays store objects as references
but destructor is called for array element causing destructor be called twice
 
1:17 AM
found it, thank you )))
 
2:12 AM
Could I violate strict aliasing by creating std::string_view from pointers of arbitrary data, or I can just assume string_view is safe because it only uses a const char* pointer?
 
 
9 hours later…
11:11 AM
What if I force it like (http://coliru.stacked-crooked.com/a/5a1c32065c4af57d) [this] , what happens there? How is it copied? I can see that `foo.a_ptr` has a valid address of the pointee (unsurprisingly) and `boo.a_ptr` points to nullptr (as far as I can see). So does it just ignore the copy ctor and initialize `a_ptr` to default value which is `nullptr`?
(Sorry for not asking this yesterday while we were on topic. I just thought of it now.)
and Idk why the link thing isnt working, I changed the order at the end, it didnt work like [this](somelink)
 
What do you mean ignore the copy ctor? it uses it just fine
but you never set a_ptr in the copy ctor
you only set a_v but that's not related at all
 
@PeterT Yes. Because if I dont make a custom copy ctor to do something there and try to activate default copy ctor of unique_ptr, it doesnt allow you to have implicit one if you have a unique_ptr in your class
 
ok, you still don't initialize a_ptr
 
I do know that, I do that intentionally
because I want to understand what it does by defualt
perhaps a_v was redundant
 
well by default it calls the default constructor of unique_ptr
which sets it to a nullptr
 
11:17 AM
why cant it do that when I do not explicitly define the copy ctor?
 
because then it would try to copy the unique_ptr
and the unique_ptr copy constructor is intentially deleted
the defaulted copy constructor implementation tries to copy every member
 
@PeterT Oh right. I am sorry. I thought that even in this case, it would try to do the same (i.e. to try to copy a_ptr) because I didnt initialize it in the explicitly defined copy ctor. But that doesnt make sense, I just understood, the problem was that I wasnt sure how copy ctors work entirely
Thanks
 
 
3 hours later…
2:29 PM
Is it a bad practice not to use curly brackets for scopes of loops and ifs etc if the posterior line is a single line?
 
@MuhamedCicak it's a style question, people disagree about it
imho it kind of depends if you have a static-analyzer or compiler that detects misleading indentation if someone adds a second indented line
 
@PeterT I see... And (in your opinion) which one is more readable?
 
personally I allow bare statements after some control flow but I typically use a formatter to avoid that class of bugs
 
I'm going to be honest, I'm not very consistent about it. Some days I do it one way, some days another. So maybe you should ask someone that's more consistent about it
 
yeah for me it really depends on the exact bit of code and my mood that day
 
2:39 PM
Yeah I see... You guys are similar to what I am about it xD Thanks for your input though :)
 
 
4 hours later…
6:39 PM
@MuhamedCicak My personal preference is to avoid the extra visual "noise" of unnecessary braces, but it seems to me that a substantial majority prefer to use braces even when they're not strictly necessary, so I at least try to consistently include them.
 

« first day (1134 days earlier)      last day (1710 days later) »