mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Population: Add operator+()
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <tools/yulPhaser/Program.h>
|
||||
|
||||
#include <libsolutil/CommonData.h>
|
||||
#include <libsolutil/CommonIO.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -117,6 +118,13 @@ void Population::run(optional<size_t> _numRounds, ostream& _outputStream)
|
||||
}
|
||||
}
|
||||
|
||||
Population operator+(Population _a, Population _b)
|
||||
{
|
||||
assert(toString(_a.m_program) == toString(_b.m_program));
|
||||
|
||||
return Population(_a.m_program, move(_a.m_individuals) + move(_b.m_individuals));
|
||||
}
|
||||
|
||||
ostream& phaser::operator<<(ostream& _stream, Population const& _population)
|
||||
{
|
||||
auto individual = _population.m_individuals.begin();
|
||||
|
||||
@@ -28,6 +28,17 @@
|
||||
namespace solidity::phaser
|
||||
{
|
||||
|
||||
class Population;
|
||||
|
||||
}
|
||||
|
||||
// This operator+ must be declared in the global namespace. Otherwise it would shadow global
|
||||
// operator+ overloads from CommonData.h (e.g. the one for vector) in the namespace it was declared in.
|
||||
solidity::phaser::Population operator+(solidity::phaser::Population _a, solidity::phaser::Population _b);
|
||||
|
||||
namespace solidity::phaser
|
||||
{
|
||||
|
||||
/**
|
||||
* Information describing the state of an individual member of the population during the course
|
||||
* of the genetic algorithm.
|
||||
@@ -74,6 +85,7 @@ public:
|
||||
);
|
||||
|
||||
void run(std::optional<size_t> _numRounds, std::ostream& _outputStream);
|
||||
friend Population (::operator+)(Population _a, Population _b);
|
||||
|
||||
std::vector<Individual> const& individuals() const { return m_individuals; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user