Skip to content

Commit

Permalink
Use std::get to access Array elements
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Feb 2, 2024
1 parent 656311f commit aeea4f4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions modules/display/include/geometry_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
: display::PairGeometry(pp) {} \
display::Geometries get_components() const override { \
display::Geometries ret; \
Decorator d0(get_particle_pair()[0]); \
Decorator d1(get_particle_pair()[1]); \
Decorator d0(std::get<0>(get_particle_pair())); \
Decorator d1(std::get<1>(get_particle_pair())); \
action; \
return ret; \
} \
Expand All @@ -180,8 +180,8 @@
display::Geometries get_components() const override { \
display::Geometries ret; \
for(ParticleIndexPair pip : get_container()->get_contents()) { \
Decorator d0(get_container()->get_model(), pip[0]); \
Decorator d1(get_container()->get_model(), pip[1]); \
Decorator d0(get_container()->get_model(), std::get<0>(pip)); \
Decorator d1(get_container()->get_model(), std::get<1>(pip)); \
action; \
} \
return ret; \
Expand Down
3 changes: 2 additions & 1 deletion modules/display/src/particle_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ SingletonsGeometry::SingletonsGeometry(SingletonContainerAdaptor pc, Color c)
: Geometry(c, pc->get_name() + " geometry"), sc_(pc) {}

PairGeometry::PairGeometry(const ParticlePair &p)
: Geometry(p.get_name() + " geometry"), p0_(p[0]), p1_(p[1]) {}
: Geometry(p.get_name() + " geometry"),
p0_(std::get<0>(p)), p1_(std::get<1>(p)) {}

PairsGeometry::PairsGeometry(PairContainer *pc)
: Geometry(pc->get_name() + " geometry"), sc_(pc) {}
Expand Down
4 changes: 2 additions & 2 deletions modules/kernel/include/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class SparseSymmetricPairMemoizer {
Generator gen_;
Checker checker_;

static Key get_0(Entry e) { return e[0]; }
static Key get_1(Entry e) { return e[1]; }
static Key get_0(Entry e) { return std::get<0>(e); }
static Key get_1(Entry e) { return std::get<1>(e); }

// The This:: is needed to make certain gcc versions (4.7) happier
typedef boost::multi_index::global_fun<Entry, Key, &This::get_0> P0Member;
Expand Down
9 changes: 4 additions & 5 deletions modules/kernel/src/internal/swig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ const Particles &_give_particles(Model *m) {
const Particles &_pass_particles(const Particles &ps) { return ps; }
Particle *_pass_particle(Particle *ps) { return ps; }
const ParticlePair &_pass_particle_pair(const ParticlePair &pp) {
for (unsigned int i = 0; i < 2; ++i) {
std::cout << pp[i]->get_name() << " ";
}
std::cout << std::endl;
std::cout << std::get<0>(pp)->get_name() << " ";
std::cout << std::get<1>(pp)->get_name() << std::endl;
return pp;
}
Particles _give_particles_copy(Model *m) {
Expand Down Expand Up @@ -148,7 +146,8 @@ ParticleIndexes _create_particles_from_pdb(std::string name, Model *m) {

Float _LogPairScore::evaluate_index(Model *m, const ParticleIndexPair &ipp,
DerivativeAccumulator *) const {
ParticlePair pp(m->get_particle(ipp[0]), m->get_particle(ipp[1]));
ParticlePair pp(m->get_particle(std::get<0>(ipp)),
m->get_particle(std::get<1>(ipp)));
if (map_.find(pp) == map_.end()) {
map_[pp] = 0;
}
Expand Down
27 changes: 16 additions & 11 deletions modules/kernel/test/test_pair_memoizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct SortedPairs {
}
std::cout << "Returning ";
for (unsigned int i = 0; i < ret.size(); ++i) {
std::cout << *ret[i][0] << "-" << *ret[i][1] << " ";
std::cout << *std::get<0>(ret[i]) << "-" << *std::get<1>(ret[i]) << " ";
}
std::cout << std::endl;
return ret;
Expand All @@ -118,16 +118,21 @@ struct SortedPairs {
struct SetEquals {
struct LessPair {
bool operator()(IMP::Entry a, IMP::Entry b) const {
if (a[0] > a[1]) std::swap(a[0], a[1]);
if (b[0] > b[1]) std::swap(b[0], b[1]);
if (a[0] < b[0])
if (std::get<0>(a) > std::get<1>(a)) {
std::swap(std::get<0>(a), std::get<1>(a));
}
if (std::get<0>(b) > std::get<1>(b)) {
std::swap(std::get<0>(b), std::get<1>(b));
}
if (std::get<0>(a) < std::get<0>(b)) {
return true;
else if (a[0] > b[0])
} else if (std::get<0>(a) > std::get<0>(b)) {
return false;
else if (a[1] < b[1])
} else if (std::get<1>(a) < std::get<1>(b)) {
return true;
else
} else {
return false;
}
}
};
bool operator()(SortedPairs::result_type t0) const {
Expand All @@ -136,11 +141,11 @@ struct SetEquals {
std::sort(t1.begin(), t1.end(), LessPair());
std::cout << "Comparing " << t0 << " and " << t1 << "= ";
for (unsigned int i = 0; i < t0.size(); ++i) {
std::cout << *t0[i][0] << "-" << *t0[i][1] << " ";
std::cout << *std::get<0>(t0[i]) << "-" << *std::get<1>(t0[i]) << " ";
}
std::cout << " and ";
for (unsigned int i = 0; i < t1.size(); ++i) {
std::cout << *t1[i][0] << "-" << *t1[i][1] << " ";
std::cout << *std::get<0>(t1[i]) << "-" << *std::get<1>(t1[i]) << " ";
}
std::cout << std::endl;
if (t0.size() != t1.size()) return false;
Expand All @@ -156,12 +161,12 @@ typedef IMP::SparseSymmetricPairMemoizer<SortedPairs, SetEquals> Table;
struct Sum {
int value;
Sum() : value(0) {}
void operator()(IMP::Entry a) { value += *a[0] + *a[1]; }
void operator()(IMP::Entry a) { value += *std::get<0>(a) + *std::get<1>(a); }
};

struct Show {
void operator()(IMP::Entry a) {
std::cout << *a[0] << "-" << *a[1] << ", ";
std::cout << *std::get<0>(a) << "-" << *std::get<1>(a) << ", ";
}
};

Expand Down
4 changes: 2 additions & 2 deletions modules/score_functor/include/SphereDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class SphereDistance : public BaseDistanceScore {
typedef BaseDistanceScore P;
static double get_rsum(Model *m,
const ParticleIndexPair &pi) {
return m->get_sphere(pi[0]).get_radius() +
m->get_sphere(pi[1]).get_radius();
return m->get_sphere(std::get<0>(pi)).get_radius() +
m->get_sphere(std::get<1>(pi)).get_radius();
}

public:
Expand Down
8 changes: 4 additions & 4 deletions modules/score_functor/include/Statistical.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class Statistical : public Score {
if (distance >= threshold_ || distance < 0.001) {
return 0;
}
int pt = m->get_attribute(key_, pp[0]);
int lt = m->get_attribute(key_, pp[1]);
int pt = m->get_attribute(key_, std::get<0>(pp));
int lt = m->get_attribute(key_, std::get<1>(pp));
if (pt == -1 || lt == -1) return 0;
return table_->get_score(pt, lt, distance);
}
Expand All @@ -101,8 +101,8 @@ class Statistical : public Score {
if (distance >= threshold_ || distance < 0.001) {
return DerivativePair(0, 0);
}
int pt = m->get_attribute(key_, pp[0]);
int lt = m->get_attribute(key_, pp[1]);
int pt = m->get_attribute(key_, std::get<0>(pp));
int lt = m->get_attribute(key_, std::get<1>(pp));
if (pt == -1 || lt == -1) return DerivativePair(0, 0);
return table_->get_score_with_derivative(pt, lt, distance);
}
Expand Down
8 changes: 4 additions & 4 deletions modules/score_functor/include/internal/PMFTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ struct PMFTable : public Object {
}
const RawOpenCubicSpline &get(int i, int j) const {
Array<2, int> is;
is[0] = i;
is[1] = j;
std::get<0>(is) = i;
std::get<1>(is) = j;
typename Storage::ExtendedIndex ei(is.begin(), is.end());
return data_[data_.get_index(ei)];
}
Expand Down Expand Up @@ -137,8 +137,8 @@ struct PMFTable : public Object {
}
order(i, j);
Array<2, int> is;
is[0] = i;
is[1] = j;
std::get<0>(is) = i;
std::get<1>(is) = j;
typename Storage::ExtendedIndex ei(is.begin(), is.end());
if (!data_.get_has_index(ei)) {
data_.add_voxel(ei, score_functor::internal::RawOpenCubicSpline(
Expand Down

0 comments on commit aeea4f4

Please sign in to comment.