|
Time to whip out a lambda function...
Steve
|
|
|
|
|
Using a Lambda here was a bit pointless, I've been so completely wrapped up in saying "Coo, aren't lambda's wonderful?" that I'd completely forgotten about std::divide which is a fair bit easier to read.
Although they do get rid of the need to do the std::bind2nd, which can only be a good thing!
Cheers,
Ash
|
|
|
|
|
I don't know, many people who aren't use to functional programming and function objects find the bind2nd and divides stuff perplexing. Even if you're use to it, if the logic gets even moderately more complex it gets very arcane and the lamda expression will be a lot simpler. My concern is that barely any people would be using a compiler that supports them yet.
Steve
|
|
|
|
|
One advantage Lambdas have over a lot of other C++ features that have been introduced in the past is that two of the more mainstream compilers are supporting them before the C++0x standard's even been voted in. Compare that to the 5 year lag a certain compiler manufacturer had with the last standard and I'm hopeful they'll be mainstream fairly soon.
Having said that I'm depressed at the number of people using VC++ 6 on this board so maybe by 2020 we'll see the mainstream get there
Cheers,
Ash - who doesn't usually hijack threads like this
|
|
|
|
|
Thanks for your help Ash. I'm currently doing the following and it works! However, how could I send "op_divide" another parameter? I don't always want to divide by "5", I'd like to send "op_divide" the denominator to use.
long double op_divide (long double d) { return d/5; }
transform (vec1.begin(), vec1.end(), vec2.begin(), op_divide);
Thanks!
|
|
|
|
|
You're using a function with a hardcoded divisor in it, so the problem is how to get a second parameter into it.
If you want to keep using a function then you can expand your function to take a second parameter:
long double op_divide( long double numerator, long double denominator ) { return numerator/denominator; }
and use std::bind2nd to create a function object to pass to transform:
transform( vec.begin(), vec1.end(), vec2.begin(), std::bind2nd( op_divide, 5.0 ) );
[That's unchecked BTW, I'm not on a computer with a compiler on to check it - I'm pretty sure it will though.]
If you're doing that you could try using std::divides which does the same thing and saves writing the function.
Cheers,
Ash
|
|
|
|
|
Thanks Ash. I implemented the code, but it is giving many errors, the first being:
error C2825: '_Fn2': must be a class or namespace when followed by '::'
and the 2nd:
error C2039: 'first_argument_type' : is not a member of '`global namespace''
|
|
|
|
|
Ooops, forgot to add in the bit of special sauce to convert the binary function pointer to a function object:
std::transform( input.begin(), input.end(), output.begin(), std::bind2nd( std::ptr_fun( op_divide ), 5 ) ) );
What you've got is a function that takes two arguments. The std::ptr_fun function returns a function object, the function call operator of which passes the arguments to the contained function. The std::bind2nd returns another function object:
- the function call operator takes 1 parameter
- the constructor of the object stores another parameter
- the function call operator passes the 1 parameter and the stored parameter through to the contained binary function object which passes them through to the contained function pointer.
Arrrgggghhhhh... I want me Lambda's back!
Cheers,
Ash
PS: That's as clear as mud, I'll try and clean it up later
|
|
|
|
|
worked great, thanks Ash!
|
|
|
|
|
Here's one way:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
vector<double> nums;
for (int i=1; i<=10; ++i)
nums.push_back(i);
cout << "Before: ";
copy(nums.begin(), nums.end(), ostream_iterator<double>(cout, " "));
cout << endl << endl;
transform(
nums.begin(), nums.end(),
nums.begin(),
bind2nd(divides<double>(), 2.0)
);
cout << "After: ";
copy(nums.begin(), nums.end(), ostream_iterator<double>(cout, " "));
cout << endl << endl;
return 0;
}
Steve
|
|
|
|
|
|
Hi guys how can i accomplish this i need to show a do you want to update message every time the app is started the first time windows has rebooted.
Thanks!!
|
|
|
|
|
You could check for a 'flag' in some configuration file or the registry. After your app runs, set the flag to some other value (or remove it).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
ok, but how do you detect that windows has reboot??, i mean i put a registry key called "doUpdate" value=false then i start my app i change that registry to true, so the next i launch my app it will not show the message that is ok, but how to reset that value when windows is restarted?
|
|
|
|
|
You might could take advantage of the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key by putting a small app there that runs the next time Windows is started.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
ok i did that but every time windows starts up i shows the black window and then closes is kind of anoying is there a parameter to put there so it runs silently?
|
|
|
|
|
It shows a black window because you made a console application.
Make a normal win32 one, just don't create any windows.
Have it set a registry value
(eg) HKCU\Software\ManchukuoSoft\MyAmazingApp\Rebooted = 1
Then, when your real MyAmazingApp is run, check the value, and maybe show a message. Then clear that value.
Job done!
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
Thanks guys that did the work!!! . This is Fixed
|
|
|
|
|
Perhaps you could create a registry key using RegCreateKeyEx[^] and use REG_OPTION_VOLATILE as the option.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
you will need 2 programs for this. One will run as autorun (startup) and set a value in registry (say reboot = true). Another program whent started by user, will check this value in registry and if it is true then display your messagebox and set the value to false.
|
|
|
|
|
Has anyone tried implementing HTTPS protocol in a C++ application.
I started reading the RFC2818, but I'm confused over implementation.
|
|
|
|
|
I would recommend RFC2616[^] as a starting point and than blend it with a SSL/TLS library instead of using TCP. The library should take care of most encryption/certificates handling (e.g. have a look at OpenSSL, GnuTLS, Microsoft's CryptoAPI). Alternatively use a library from the shelf that offer HTTPS (e.g. libcurl, WinInet, QHttp).
You need to decide if you want to implement everything yourself or take an existing C++ library. First will teach you a lot about networking protocols, later gives you the result right away. Hope this helps!
/M
|
|
|
|
|
Moak wrote: First will teach you a lot about networking protocols, later gives you the result right away.
Nice reply in general. I'd change the bit I quoted to read as follows:
The first will teach you a lot about networking protocols and convince you to go with the second.
Steve
|
|
|
|
|
Hi i have an MFc application which is compiled in Visual studio 6 .
I have created a dll that is compiled in VS2005.
It works fine on development machine giving me all desired results.
But after deploying the exe and dll on Other machine which is meant to be for testing purpose. I copied all the dependent dll in the same folder is required for dll that is compiled on VS2005.
But the dll is failed to load using loadlibrary.
To solve this issue i created a setup of MSM of Visual studio Merge module and installed on the Testing machine. I was expecting that this will atleast solve my prioblem but it also failed to load dll.
Any one has suggestion that how this can be achieved?
|
|
|
|
|
try Depends[^] to see if there are any missing DLLs.
|
|
|
|