« first day (115 days earlier)      last day (2756 days later) » 

12:55 AM
Can somebody help me with function pointers?
I am trying to write a comparison function that takes in a function int f (int) and two int values and returns f(a) < f(b)
However I need this function to return a function pointer instead that would do such a thing
I am having a bit of a headache with the syntax
So something like this
bool(*F(double(*f)(int)))(int, int)
{
return [](int a, int b) { return f(a) < f(b); };
}
There must be a better way to do this? This is really hard to read
 
1:20 AM
@AliCaglayan no
@AliCaglayan good work, keep it up, #proudofyou
@AliCaglayan Nice, code it in
@AliCaglayan Aspirin/paracetamol
@AliCaglayan Did you go to an optician recently? Check yer glasses
 
auto func = [](auto f)
{
return [=](int a, int b) { return f(a) < f(b); };
};
 
@EvgenyPanasyuk Stop it
We troll lil bitches like that guy here
not help them
 
@набиячлэвэли I am not helping.
 
user406009
@AliCaglayan Sorry, for the confusion, but questions are sort of banned here. I'm more than happy to help you in the question room though: chat.stackoverflow.com/rooms/116940/c-questions-and-answers
 
user406009
@AliCaglayan It's not really possible to do what you want.
 
user406009
1:29 AM
The issue is that you have to store state about f somewhere.
 
user406009
Instead of using a function pointer, you might want to consider using std::function instead.
 
user406009
std::function<bool(int, int)> F(double(*f)(int))
{
return [f](int a, int b) { return f(a) < f(b); };
}
 
user406009
Note that you have to capture f.
 
1:43 AM
@Lalaland Yeah, I did it another way but thanks for the offer. I didn't think that a chatroom on a site about questions wouldn't want questions.
 
> "Does anybody know how to file taxes?"
> "Sir, you're in a bar"
> "Yes, I know, but many of the people here are accountants"
We're totally cool with questions in this room, but buy us a drink first. As Lalaland mentions, we have cozy rooms where problems can be discussed at length without noise.
 
user406009
@AliCaglayan Yeah, I also wish they would change that rule on here. But I don't make the rules. And some people care a lot about that one rule.
 
user406009
@Mikhail Not quite the same. Ali wanted to use some scoring function f.
 
user406009
I guess you are right in a sense that you can use templates to avoid storing f explicitly.
 
3:16 AM
Indeed, he is doing something that isn't paradigmatic, which is the worst sin
 
@AliCaglayan If you really need a pointer to a function (you don't), always start with a typedef or using to give a name to the pointer to function type.
 
 
4 hours later…
7:34 AM
27 messages moved from Lounge<C++>
@AliCaglayan As you've probably found out by now this should have been on Stack Overflow so it could have been answered by referring to the many many duplicates.
@Michele Yes. This was on Stack Overflow by the way:
21
Q: C++ - value of uninitialized vector<int>

anonI understand from the answer to this question that values of global/static uninitialized int will be 0. The answer to this one says that for vectors, the default constructor for the object type will be called. I am unable to figure out - what happens when I have vector<int> v(10) in a loca...

This but one of many related posts
@Michele And this says exactly nothing. What you want to know is what the compiler is required to do, because you don't want to break your software on the next compile/compiler update
 
 
8 hours later…
3:58 PM
anyone on ?
 
Ven
no
 
user1804599
The avatars are all undimmed but nobody is here no
 
4:11 PM
can someone tell me how do i do hashing of string with another string ?
 
4 messages moved from Lounge<C++>
@jagdish what do you mean? A cryptographic digest? Combined hashing of multiple values?
47
Q: How do I combine hash values in C++0x?

Neil GC++0x adds hash<...>(...). I could not find a hash_combine function though, as presented in boost. What is the cleanest way to implement something like this? Perhaps, using C++0x xor_combine?

 
can you see this image here?
here h1 = m1 where m1 is a block of string(2 size)
 
You're looking for a combined hash here. Is it ok for H("a", "b") to be equal to H("ab", "") ?
IOW: is there information in the structure of substrings, or is it really just appending more data (the latter is very usual in digests)
 
why are you posting screenshots of homework? I'm not doing your homework
I asked you a question though. If you care, you could start there
 
Thanks i got it
it is not homework i m working as freelancer and it sucks
it really sucks
 
 
2 hours later…
user5378087
6:56 PM
Is illegal use a dynamic_cast from a pointer of base type to a pointer to derived type, if the pointer to base being pointed to a base object? I mean:
 
user5378087
Base* b = new Base( );
Derived* d = dynamic_cast<Derived*>( b );
 
user5378087
AFAIK, this dynamic_cast returns null (a call to one function from that derived pointer will crash the program). Why? Is it a rule that I can't use a base objects as a derived?

Curiously, if I use static_cast and call to one function from that derived pointer, being overrided from a virtual function or being a specific function from the derived class, the program runs normally. It seems that the object was converted from base to derived.
 
illegal? no. it just returns null
doing static_cast, however, is illegal
 
nwp
@BIG-95 that is the feature of dynamic_cast, it gives you a nullptr instead of a valid looking pointer that you must not dereference
 
user5378087
but why does use static_cast in that last code the program run?
 
user5378087
7:00 PM
Derived* d = static_cast<Derived*>( b );
d->abc( );
 
you've just shot yourself in the leg and you aren't aware of it yet
 
user5378087
you know, when we're learning something, we're lost...
 
user406009
@BIG-95 It might run in some cases, but it won't run in every case. It's undefined behavior.
 
nwp
@BIG-95 It is undefined behavior. Meaning the standard gives no guarantee for what happens. Maybe it crashes, maybe it does exactly what you want. You never know. Try to avoid that situation.
 
user406009
Even just changing compiler optimizer settings could break it.
 
user5378087
7:02 PM
 
nwp
So what are you trying to achieve with this crazy code?
 
user406009
@BIG-95 Yeah, that example only works correctly due to a number of very specific optimizations.
 
user406009
It will break like crazy with minor changes.
 
user5378087
but, in terms of design or correctness, I should never cast a base object to a derived (I think that I need to revise some OOP terms, like inheritance)?
 
user5378087
@nwp like I said, I was doubtful...
 
7:06 PM
static_cast from Base* to Derived* is only legal if the pointer was originally pointing to a Derived object
 
user406009
Correct. You should never cast a base object to a derived. Dynamic cast does the right thing and gives you null back. Just be sure to manually check that null.
 
nwp
@BIG-95 Ok, now you know :D
 
user406009
That was the mistake in that question you pointed out. OP didn't manually check for NULL.
 
user5378087
Ok guys, I got it! Thanks a lot...
 
nwp
@milleniumbug When I try to pin your message it says You have already voted, but the voting has been cleared by a moderator. Report as a bug on meta?
I'm fairly sure no moderator came in and unpinned that message.
 
7:12 PM
hehe, yeah, it's probably a bug
this happens
there's also "You have starred and pinned this message"
if you follow the transcript to a message you've starred you get this message
which is funny especially when you're in a room where you can't pin messages because you aren't the owner
the automatic unpinning is quite annoying
 
nwp
From inside the transcript it just gives me the option to unpin it. I guess the automatic unpinning script is technically a moderator.
 
this is pretty much the reason Lounge<C++> has to remind itself to write a new rules reminder message every several weeks
I have the option "unpin this message", it's just it doesn't seem to do anything
 
nwp
@milleniumbug same, but if you try from the starboard it shows the error
"Down with the moderator (script)!"
not quite witty enough, but something in that direction
"Stop vote-suppression by moderators!"
Seems like decent enough click-bait.
The actual bug-report/feature-request would be to change the message to "This message has been unpinned automatically and cannot be re-pinned.", but that doesn't seem important enough.
 
 
4 hours later…
11:26 PM
@Lalaland Even just compiling it again might
@nwp pinned
 
nwp
cool thanks
I suppose 1 pinning per room owner
weird system
 
11:56 PM
@nwp Excessive pining would make you look desperate and pitiful.
 

« first day (115 days earlier)      last day (2756 days later) »