Commit e8a1a550 authored by Jason Rhinelander's avatar Jason Rhinelander

Fixed for gcc compilation

gcc doesn't seem to like my class member struct arguments being out of
order, so fixed that.

The bigger problem is the hack (adding what should be an unneeded
template type) to all_combinations, because gcc doesn't seem to be
handling typename It::value_type properly.
parent 239463f2
......@@ -34,17 +34,24 @@ namespace eris {
* combination of parameters. The argument is a new unique list of elements of the input
* set. Despite being in a vector, these values should really be treated as a set. Values
* will be in the same order as encountered in the input iterator.
* \param T the underlying data type template parameter is required, unfortunately. This shouldn't
* be necessary at all, since it is obtainable from the class of the given iterator, but gcc
* (as of 4.8.1) chokes on that, hence the additional (required) template parameter.
template <typename It>
// FIXME: this first 'T' template parameter shouldn't be needed (and isn't, if using clang++), but
// g++ needs it, so everything has to deal with it. Try again, eventually, to remove it, changing
// the 'T' types below to 'typename It::value_type'.
template <typename T, typename It>
typename std::enable_if<std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<It>::iterator_category>::value>::type
const It &begin,
const It &end,
std::function<void(const std::vector<typename It::value_type> &)> func
std::function<void(const std::vector<T> &)> func
) {
// Store the current combination being considered
std::vector<typename It::value_type> combination; // Will store the current combination being considered
std::vector<T> combination; // Will store the current combination being considered
// The first combination is always the empty set; call with it:
// Test script to work out how to get all combinations of size 2 or above from a set of elements.
#include <eris/algorithms.hpp>
#include <eris/types.hpp>
#include <set>
#include <unordered_set>
#include <stack>
......@@ -8,8 +9,9 @@
#include <iostream>
using std::cout;
using eris::eris_id_t;
void print_vec(const std::vector<int> &v) {
void print_vec(const std::vector<eris_id_t> &v) {
cout << "[";
bool first = true;
for (auto vi : v) {
......@@ -23,7 +25,7 @@ void print_vec(const std::vector<int> &v) {
int main() {
std::set<int> permute;
std::set<eris_id_t> permute;
......@@ -32,44 +34,12 @@ int main() {
eris::all_combinations(permute.begin(), permute.end(), print_vec);
eris::all_combinations(permute.crbegin(), permute.crend(),
[](const std::vector<int> &comb) -> void { print_vec(comb); });
eris::all_combinations<eris_id_t>(permute.begin(), permute.end(), print_vec);
eris::all_combinations<eris_id_t>(permute.crbegin(), permute.crend(),
[](const std::vector<eris_id_t> &comb) -> void { print_vec(comb); });
std::unordered_set<int> pb;
std::unordered_set<eris_id_t> pb;
eris::all_combinations(pb.cbegin(), pb.cend(), print_vec);
std::vector<int> combination;
std::stack<std::set<int>::const_iterator> it_stack;
auto end = permute.cend();
int iters = 0;
while (!it_stack.empty()) {
auto it =;
if (combination.size() > 1) {
auto n = std::next(it);
if (n == end) {
// We're at the end, so we need to pop ourselves and our value off the stack
// Also pop off the previous value and increment it (the incremented value is going to
// be pushed back on in the next iteration).
if (!it_stack.empty());
cout << iters << " loop iterations\n";
eris::all_combinations<eris_id_t>(pb.cbegin(), pb.cend(), print_vec);
......@@ -127,7 +127,7 @@ bool IncrementalBuyer::oneRound() {
// From everything added into permute, above, we need to build all possible multi-element
// combinations; e.g. if permute = {1,2,3} we have 4 possibilities: {1,2}, {1,3}, {2,3}, {1,2,3}
eris::all_combinations(permute.cbegin(), permute.cend(),
eris::all_combinations<eris_id_t>(permute.cbegin(), permute.cend(),
[&](const std::vector<eris_id_t> &combination) -> void {
int comb_size = combination.size();
......@@ -36,7 +36,7 @@ Market::quantity_info QMarket::quantity(double p) const {
bool constrained = q > available;
if (constrained) q = available;
double spent = constrained ? price_*q : p;
return { .constrained=constrained, .quantity=q, .spent=spent, .unspent=p-spent };
return { .quantity=q, .constrained=constrained, .spent=spent, .unspent=p-spent };
Market::Reservation QMarket::reserve(double q, Bundle *assets, double p_max) {
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment