According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include after #include and before your code, preferably not in the global namespace so here's a demo of proper namespace use:
#include <iostream>
#include <cmath> // Uses ::log, which would be the log() here if it were not in a namespace, see httphttps://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace
// Silently overrides std::log
//double log(double d) { return 420; }
namespace uniquename {
using namespace std; // So we don't have to waste space on std:: when not needed.
double log(double d) {
return 42;
}
int main() {
cout << "Our log: " << log(4.2) << endl;
cout << "Standard log: " << std::log(4.2);
return 0;
}
}
// Global wrapper for our contained code.
int main() {
return uniquename::main();
}
Output:
Our log: 42
Standard log: 1.43508
Your new GA code is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace so here's a demo of proper namespace use:
#include <iostream>
#include <cmath> // Uses ::log, which would be the log() here if it were not in a namespace, see http://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace
// Silently overrides std::log
//double log(double d) { return 420; }
namespace uniquename {
using namespace std; // So we don't have to waste space on std:: when not needed.
double log(double d) {
return 42;
}
int main() {
cout << "Our log: " << log(4.2) << endl;
cout << "Standard log: " << std::log(4.2);
return 0;
}
}
// Global wrapper for our contained code.
int main() {
return uniquename::main();
}
Output:
Our log: 42
Standard log: 1.43508
Your new GA code is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace so here's a demo of proper namespace use:
#include <iostream>
#include <cmath> // Uses ::log, which would be the log() here if it were not in a namespace, see https://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace
// Silently overrides std::log
//double log(double d) { return 420; }
namespace uniquename {
using namespace std; // So we don't have to waste space on std:: when not needed.
double log(double d) {
return 42;
}
int main() {
cout << "Our log: " << log(4.2) << endl;
cout << "Standard log: " << std::log(4.2);
return 0;
}
}
// Global wrapper for our contained code.
int main() {
return uniquename::main();
}
Output:
Our log: 42
Standard log: 1.43508
Your new GA code is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace . so here 's a demo of proper namespace use:
#include <iostream>
#include <cmath> // Uses ::log, which would be the log() here if it were not in a namespace, see http://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace
// Silently overrides std::log
//double log(double d) { return 420; }
namespace uniquename {
using namespace std; // So we don't have to waste space on std:: when not needed.
double log(double d) {
return 42;
}
int main() {
cout << "Our log: " << log(4.2) << endl;
cout << "Standard log: " << std::log(4.2);
return 0;
}
}
// Global wrapper for our contained code.
int main() {
return uniquename::main();
}
This versionOutput:
Our log: 42
Standard log: 1.43508
Your new GA code is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace .
This version is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace so here 's a demo of proper namespace use:
#include <iostream>
#include <cmath> // Uses ::log, which would be the log() here if it were not in a namespace, see http://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace
// Silently overrides std::log
//double log(double d) { return 420; }
namespace uniquename {
using namespace std; // So we don't have to waste space on std:: when not needed.
double log(double d) {
return 42;
}
int main() {
cout << "Our log: " << log(4.2) << endl;
cout << "Standard log: " << std::log(4.2);
return 0;
}
}
// Global wrapper for our contained code.
int main() {
return uniquename::main();
}
Output:
Our log: 42
Standard log: 1.43508
Your new GA code is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim, Boo, and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug, nor many memory management mistakes.)
- 343
- 4
- 14
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace.
This version is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements (inin favor of more inline documentation), e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim , Boo , and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug , nor many memory management mistakes.)
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace.
This version is about 100 lines longer than your previous version; did you add that much functionality? I'd leave out the curly braces of the single statements (in favor of more inline documentation), e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
++i
is slightly faster than i++
, but the compiler should optimize that already.
According to this great video, using namespace std;
allows you to leave out the many std::
bits. Use using
after #include and before your code, preferably not in the global namespace.
This version is about 100 lines longer than your previous version; did you add that much functionality? I prefer more context per screen, so I'd leave out the curly braces of the single statements in favor of more inline documentation, e.g.:
for (i = 1; i < POPULATION; ++i)
for (j = 0; j < PUZZLE; ++j)
if (mutation_rand(gen) <= MUTATION)
pieces[i].ADN[j] = (int)dist(gen);
But people who don't mind curly braces might mess that up. Safer alternatives are Nim , Boo , and Python (Cython or PyPy for speed).
++i
is slightly faster than i++
, but the compiler should optimize that already. (Not sure, since C++ compilers didn't catch the dead code that led to Apple's SSL bug , nor many memory management mistakes.)