« first day (3464 days earlier)      last day (1467 days later) » 

12:43 AM
I knew it was painful for them. But first time I hear it could literally kill a cow. I guess they can control by milking them a bit less to gradually reduce the output but it takes time for the body to adapt.
 
 
8 hours later…
8:27 AM
Can I convert a C file into a C++ file by changing the name to .cpp, then wrapped all the code in 'extern C'?
 
@TelKitty for a lot of C code, but not for all
for headers it mostly works, but if it's *.c code it would be common to rely on implicit void* conversions and other stuff
 
 
2 hours later…
10:53 AM
 
11:27 AM
Pretty sure C does implicit Cast on stuff by default
But still, only one way to know if you can is to try it. If you're lucky it will work without much required changes.
Still easier to convert C to C++ than C to Javascript
 
aye, that said the weirder things I've run into that are technically UB in C++ but used extensively in C are things like the struct hack
 
12:21 PM
The struct hack?
 
nwp
Array of indetermined size at the end I think. I forgot what the proper term was for that.
 
Flexible array member?
 
@Morwenn pretty much what nwp said, and yes it's also know as that
but it's very very very much UB in C++
that said it's ubiquitous in C code and in a lot of legacy C++
 
Actually C++ implicitly has first-class support for such things but goes through great lengths to make sure it's not discoverable
Only since C++20 though
 
12:33 PM
I'm not even talking about non-standard C++ :D
 
my point is that it's still not technically supported unless something massive changed in C++20
due to really weird padding rules
 
That's exactly what I linked to: a way to do it in C++20
Not with the same syntax, but the result is the same: you allocate a class instance with a variable size after it, and delete takes care of it properly
 
IIRC the issue isn't just delete it's also new
it's been too long since I watched the video to call out the specific issues
 
operator new has had class-specific overloads forever
 
but there are some serious quirks
 
12:37 PM
Read the damn paper x)
 
was that accepted?
 
Yes, it's in C++20
It's already implemented in GCC, Clang and MSVC
It is amongst the features that seldom has any documentation or examples and nobody talks about it seems
 
1:23 PM
@Morwenn I guess I'll have to update my hack_ptr to use it properly then
 
1:54 PM
@Morwenn so rereading this, it doesn't technically support legacy cases. The best you could do is inherit the legacy object using a template that creates the appropriate operators
I can't actually fix my hack_ptr as a result
 
time for hack_ptrEx then :P
 
@PeterT I think I could probably use templates carefully to make an intrusive version. But I don't think I could do a hack_ptr<T> without getting really really creative
 
any good soul wants to check out my code to find a logic error ? pls (need for university) (C,linked list using array)
 

C++ Questions and Answers

Solve problems and approach solutions. Just ask and lurkers wi...
 
yeah i posted there aswell
 
 
7 hours later…
9:21 PM
could someone explain to me please what is the difference between c++11 operator! and earlier version?
`The operator operator! is commonly overloaded by the user-defined classes that are intended to be used in boolean contexts. Such classes also provide a user-defined conversion function to boolean type (see std::basic_ios for the standard library example), and the expected behavior of operator! is to return the value opposite of operator bool.(until C++11)`


`Since the built-in operator ! performs contextual conversion to bool, user-defined classes that are intended to be used in boolean contexts could provide only operator bool and need not overload operator!.(since C++11)`
 
C++11 introduced contextual conversions to bool: some conversions to bool are implicit only in some contexts
 
so then what is the relation between operator! and operator bool?
3
Q: Overloading logical NOT operator vs bool type-cast operator

imrealConsider the following code: class Truth { public: Truth(bool val) : value(val) {} bool operator!() {std::cout<<"operator!()"<<std::endl; return !value;} operator bool() {std::cout<<"operator bool()"<<std::endl; return value;} private: bool value; }; int main() { Truth t(tru...

i've read this but doesn't help me a lot
 
For example if your class Foo has an explicit operator bool, then you can't write bool blah = Foo(); because the conversion to bool is explicit, but there are some contexts where the conversion to bool is still explicit, and ! is one such context
The places where a contextual conversion to bool happen are conditions in control statements, and when a variable that can be contextually converted to bool appears as an operand of !, && or ||
explicit operator bool is thus a tool that allows to convert a variable to bool when you want to "test" it, but not in other conditions
 
but operator bool() doesn;t have to be mandatory explicit
 
It doesn't
 
9:29 PM
so then it is very similar to operator!
 
The idea is that you can write classes where you only allow "safe" implicit conversions to bool
 
I ran into an amusing bug when trying to curry, lets see if anybody can spot it. Has to do with the return type :-)
const auto empty_check = [](virtual_camera_image& img)
{
	if (!img.img.empty())
	{
		throw std::runtime_error("Bug in image loading loop");
	}
	return img;
};
 
operator! is merely a facetof the issue
 
img.img ?
or is this about it throwin when not empty?
 
Not what one :-)
That function fails to curry
 
9:31 PM
oh because of the return type
 
Yeah
Could be const auto empty_check = [](virtual_camera_image& img) ->virtual_camera_image&
for a quick fix
 
to be fair, if the compiler did the reference automatically you'd have way people creating bugs based on that :P
 
I don't know about that. I expect to get what I put in.
 
Oh, I didn't get that you expected it to return a reference type
Not specifying the return type is equivalent to -> auto so it decays
-> decltype(auto) and return (img); would return a reference type x)
 
Oh no! Fuck this language.
 
9:35 PM
Yup, the difference between return foobar; and return (foobar); became meaningful a few years ago
 
no,no,no,no,no,no :-)
 
Sometimes this stuff just makes you laugh about how comically absurd it is
 
what is a contextual conversion? what is ment by the implicit conversion is performed if the declaration bool t(e); is well-formed
 
That wording is only used for conversions to bool in the contexts I mentioned earlier
 
So even if I don't totally understand this thnig, the new thing in c++11 is that you don't have to explicitly declare operator! as since c++11, the standard unary NOT operator calls the operator bool() in order to convert a user-defined type to bool, so that I don't have to worry about implementing operator! anymore? and if I would like a double negation I would just !!myObj?
 
9:40 PM
yes
If you want your type to behave like a boolean, just overload operator bool
 
but they are exposing this so hard to understand
@Morwenn by default does that operator bool() exists?
 
operator!, operator&& and operator|| are things you only need to overload when you do ungodly things
@CătălinaSîrbu no, you need to declare it
 
even outside class?
 
Conversion operators can only be declared in-class
 
9:44 PM
So I tried it but adding a parentheses doesn't quite work
 
It's supposed to only make a difference when you return decltype(auto)
If you don't specify the return type it decays
 
@Morwenn by conversion operators you mean explicit operator conversion-type-id (2) (since C++11)?
 
And it needs to be auto&& maybe_reference_to_original = ... because auto here decays too
@CătălinaSîrbu yeah, for example struct foobar { operator bool() const { return true; } };
 
9:50 PM
Yeah but you added the && :-)
Anyways, the example, does indeed, defeat the automatic correction for resharper's redundant parenthesis check which is worth a bug report.
 
Yeah, check my last message before yours :')
Here you can see the returned type
 
thanks a lot!
 
 
you're welcome :)
 
So, anybody working on anything cool?
I'm merging two branches, one of which is a month out of date :-(
I don't think anybody is even paying me, I'm doing it purely for the masochism!
 
10:13 PM
I tried to use AFL recently and tried to write a small genetic algorithm some time ago
But I didn't quite achieve anything
On the other hand I've made violet syrup a few times, blended cake-coated bananas, and ramens for the first time while confined and it was pretty cool
I also used an old trick to cut a glass bottle with a string, fire and cold water today but it wasn't exactly a success (I did cut it, but it was too violent)
I drank a beer with my cousin around burning moss in an avocado shell
I managed to perform one of my best moves so far a tennis table a few hours ago
I've been doing a bunch a small things unrelated to programming since the beginning of the confinement ^^
 
what is bitmask type ?
 
10:41 PM
@Morwenn Are you trying to make flower pots?
 
@CătălinaSîrbu As far as the C++ standard is concerned a bitmask type can be an unsigned integer, std::bitset or any other type that can be used as a bit mask (with overloaded bitwise operators and similar semantics)
I'm not even sure about std::bitset actually
 
also, operator functions can return whatever data type they want ? or they are forced to have the same behaviour as classical operators? (e.g < , > , returning bool)
 
@Mikhail not really, I was thinking of making a fun glasses service/set
@CătălinaSîrbu They can return anything, but you often want to overload operators in a way that makes sense
A lot of template libraries rely on the fact that the types you give them overload their operators to follow consistent semantics
That's why 95% of the overloaded operator== you see around return bool
And are consistent with an overloaded operator!=
 
hii,
does anyone know if android C++ has the same features as the one in java?
 
11:38 PM
Today I read a news how Fauci said good news in the US is that new cases seemed to decrease yet daily death continue to increase... Not sure if the good news came from him
because if death keep increasing, may be it's just counting confirming cases that can't keep up
 
There's always a 7~15 days delay to things with that virus
 
There are also reports that death could be under counted as death not occuring in hospitals aren't tested
So if a person doesn't have the money to get treated at the hospital and couldn't get tested... he might just die at home and not being reported as a confirmed case
May be today the US will have more death than every other countries.
Next phase is to have more death per capita than any other country
 
11:53 PM
That's why we're already starting to see graphs appear which compare the overall mortality over the period to try to guesstimate the amount of unreported COVID-19 deaths
 

« first day (3464 days earlier)      last day (1467 days later) »