Skip to content

Commit

Permalink
replaced boost with std for placeholders, bind and function
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Jul 11, 2021
1 parent 4ac4302 commit dc8b5e5
Show file tree
Hide file tree
Showing 32 changed files with 408 additions and 384 deletions.
4 changes: 2 additions & 2 deletions gtsam/base/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <gtsam/config.h>

#include <boost/format.hpp>
#include <boost/function.hpp>
#include <functional>
#include <boost/tuple/tuple.hpp>
#include <boost/math/special_functions/fpclassify.hpp>

Expand Down Expand Up @@ -489,7 +489,7 @@ struct MultiplyWithInverseFunction {

// The function phi should calculate f(a)*b, with derivatives in a and b.
// Naturally, the derivative in b is f(a).
typedef boost::function<VectorN(
typedef std::function<VectorN(
const T&, const VectorN&, OptionalJacobian<N, M>, OptionalJacobian<N, N>)>
Operator;

Expand Down
7 changes: 4 additions & 3 deletions gtsam/base/Testable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
#pragma once

#include <boost/concept_check.hpp>
#include <boost/shared_ptr.hpp>
#include <functional>
#include <iostream>
#include <memory>
#include <string>

#define GTSAM_PRINT(x)((x).print(#x))
Expand Down Expand Up @@ -119,10 +120,10 @@ namespace gtsam {
* Binary predicate on shared pointers
*/
template<class V>
struct equals_star : public std::function<bool(const boost::shared_ptr<V>&, const boost::shared_ptr<V>&)> {
struct equals_star : public std::function<bool(const std::shared_ptr<V>&, const std::shared_ptr<V>&)> {
double tol_;
equals_star(double tol = 1e-9) : tol_(tol) {}
bool operator()(const boost::shared_ptr<V>& expected, const boost::shared_ptr<V>& actual) {
bool operator()(const std::shared_ptr<V>& expected, const std::shared_ptr<V>& actual) {
if (!actual && !expected) return true;
return actual && expected && traits<V>::Equals(*actual,*expected, tol_);
}
Expand Down
2 changes: 1 addition & 1 deletion gtsam/base/lieProxies.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* These should not be used outside of tests, as they are just remappings
* of the original functions. We use these to avoid needing to do
* too much boost::bind magic or writing a bunch of separate proxy functions.
* too much std::bind magic or writing a bunch of separate proxy functions.
*
* Don't expect all classes to work for all of these functions.
*/
Expand Down
345 changes: 172 additions & 173 deletions gtsam/base/numericalDerivative.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gtsam/discrete/DecisionTree-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ namespace gtsam {
template<typename L, typename Y>
template<typename M, typename X>
DecisionTree<L, Y>::DecisionTree(const DecisionTree<M, X>& other,
const std::map<M, L>& map, boost::function<Y(const X&)> op) {
const std::map<M, L>& map, std::function<Y(const X&)> op) {
root_ = convert(other.root_, map, op);
}

Expand Down Expand Up @@ -568,7 +568,7 @@ namespace gtsam {
template<typename M, typename X>
typename DecisionTree<L, Y>::NodePtr DecisionTree<L, Y>::convert(
const typename DecisionTree<M, X>::NodePtr& f, const std::map<M, L>& map,
boost::function<Y(const X&)> op) {
std::function<Y(const X&)> op) {

typedef DecisionTree<M, X> MX;
typedef typename MX::Leaf MXLeaf;
Expand Down
12 changes: 7 additions & 5 deletions gtsam/discrete/DecisionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#pragma once

#include <gtsam/discrete/Assignment.h>

#include <boost/function.hpp>
#include <functional>
#include <iostream>
#include <vector>
#include <map>
#include <vector>

namespace gtsam {

Expand All @@ -38,8 +40,8 @@ namespace gtsam {
public:

/** Handy typedefs for unary and binary function types */
typedef boost::function<Y(const Y&)> Unary;
typedef boost::function<Y(const Y&, const Y&)> Binary;
typedef std::function<Y(const Y&)> Unary;
typedef std::function<Y(const Y&, const Y&)> Binary;

/** A label annotated with cardinality */
typedef std::pair<L,size_t> LabelC;
Expand Down Expand Up @@ -107,7 +109,7 @@ namespace gtsam {
/** Convert to a different type */
template<typename M, typename X> NodePtr
convert(const typename DecisionTree<M, X>::NodePtr& f, const std::map<M,
L>& map, boost::function<Y(const X&)> op);
L>& map, std::function<Y(const X&)> op);

/** Default constructor */
DecisionTree();
Expand Down Expand Up @@ -143,7 +145,7 @@ namespace gtsam {
/** Convert from a different type */
template<typename M, typename X>
DecisionTree(const DecisionTree<M, X>& other,
const std::map<M, L>& map, boost::function<Y(const X&)> op);
const std::map<M, L>& map, std::function<Y(const X&)> op);

/// @}
/// @name Testable
Expand Down
4 changes: 3 additions & 1 deletion gtsam/geometry/Cyclic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#include <gtsam/base/Group.h>
#include <gtsam/base/Testable.h>
#include <iostream> // for cout :-(

#include <cassert>
#include <iostream> // for cout :-(

namespace gtsam {

Expand Down
4 changes: 2 additions & 2 deletions gtsam/inference/EliminateableFactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#pragma once

#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <functional>
#include <boost/variant.hpp>
#include <boost/optional.hpp>

Expand Down Expand Up @@ -86,7 +86,7 @@ namespace gtsam {
typedef std::pair<boost::shared_ptr<ConditionalType>, boost::shared_ptr<_FactorType> > EliminationResult;

/// The function type that does a single dense elimination step on a subgraph.
typedef boost::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
typedef std::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;

/// Typedef for an optional variable index as an argument to elimination functions
typedef boost::optional<const VariableIndex&> OptionalVariableIndex;
Expand Down
41 changes: 29 additions & 12 deletions gtsam/inference/LabeledSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
* @author: Alex Cunningham
*/

#include <iostream>
#include <gtsam/inference/LabeledSymbol.h>

#include <boost/bind/bind.hpp>
#include <boost/format.hpp>

#include <boost/lexical_cast.hpp>

#include <gtsam/inference/LabeledSymbol.h>
#include <iostream>

namespace gtsam {

Expand Down Expand Up @@ -109,17 +106,37 @@ bool LabeledSymbol::operator!=(gtsam::Key comp) const {
/* ************************************************************************* */
static LabeledSymbol make(gtsam::Key key) { return LabeledSymbol(key);}

boost::function<bool(gtsam::Key)> LabeledSymbol::TypeTest(unsigned char c) {
return boost::bind(&LabeledSymbol::chr, boost::bind(make, boost::placeholders::_1)) == c;
std::function<bool(gtsam::Key)> LabeledSymbol::TypeTest(unsigned char c) {
// Use lambda function to check equality
auto equals = [](unsigned char s, unsigned char c) { return s == c; };
return std::bind(
equals,
std::bind(&LabeledSymbol::chr, std::bind(make, std::placeholders::_1)),
c);
}

boost::function<bool(gtsam::Key)> LabeledSymbol::LabelTest(unsigned char label) {
return boost::bind(&LabeledSymbol::label, boost::bind(make, boost::placeholders::_1)) == label;
std::function<bool(gtsam::Key)> LabeledSymbol::LabelTest(unsigned char label) {
// Use lambda function to check equality
auto equals = [](unsigned char s, unsigned char c) { return s == c; };
return std::bind(
equals,
std::bind(&LabeledSymbol::label, std::bind(make, std::placeholders::_1)),
label);
}

boost::function<bool(gtsam::Key)> LabeledSymbol::TypeLabelTest(unsigned char c, unsigned char label) {
return boost::bind(&LabeledSymbol::chr, boost::bind(make, boost::placeholders::_1)) == c &&
boost::bind(&LabeledSymbol::label, boost::bind(make, boost::placeholders::_1)) == label;
std::function<bool(gtsam::Key)> LabeledSymbol::TypeLabelTest(unsigned char c, unsigned char label) {
// Use lambda functions for && and ==
auto logical_and = [](bool is_type, bool is_label) { return is_type == is_label; };
auto equals = [](unsigned char s, unsigned char c) { return s == c; };
return std::bind(logical_and,
std::bind(equals,
std::bind(&LabeledSymbol::chr,
std::bind(make, std::placeholders::_1)),
c),
std::bind(equals,
std::bind(&LabeledSymbol::label,
std::bind(make, std::placeholders::_1)),
label));
}

/* ************************************************************************* */
Expand Down
8 changes: 4 additions & 4 deletions gtsam/inference/LabeledSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#pragma once

#include <functional>
#include <gtsam/inference/Symbol.h>
#include <boost/function.hpp>

namespace gtsam {

Expand Down Expand Up @@ -89,13 +89,13 @@ class GTSAM_EXPORT LabeledSymbol {
*/

// Checks only the type
static boost::function<bool(gtsam::Key)> TypeTest(unsigned char c);
static std::function<bool(gtsam::Key)> TypeTest(unsigned char c);

// Checks only the robot ID (label_)
static boost::function<bool(gtsam::Key)> LabelTest(unsigned char label);
static std::function<bool(gtsam::Key)> LabelTest(unsigned char label);

// Checks both type and the robot ID
static boost::function<bool(gtsam::Key)> TypeLabelTest(unsigned char c, unsigned char label);
static std::function<bool(gtsam::Key)> TypeLabelTest(unsigned char c, unsigned char label);

// Converts to upper/lower versions of labels
LabeledSymbol upper() const { return LabeledSymbol(c_, toupper(label_), j_); }
Expand Down
7 changes: 5 additions & 2 deletions gtsam/inference/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ Symbol::operator std::string() const {

static Symbol make(gtsam::Key key) { return Symbol(key);}

boost::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
return boost::bind(&Symbol::chr, boost::bind(make, boost::placeholders::_1)) == c;
std::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
auto equals = [](unsigned char s, unsigned char c) { return s == c; };
return std::bind(
equals, std::bind(&Symbol::chr, std::bind(make, std::placeholders::_1)),
c);
}

GTSAM_EXPORT std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
Expand Down
7 changes: 4 additions & 3 deletions gtsam/inference/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

#pragma once

#include <gtsam/inference/Key.h>
#include <gtsam/base/Testable.h>
#include <gtsam/inference/Key.h>

#include <boost/serialization/nvp.hpp>
#include <boost/function.hpp>
#include <cstdint>
#include <functional>

namespace gtsam {

Expand Down Expand Up @@ -114,7 +115,7 @@ class GTSAM_EXPORT Symbol {
* Values::filter() function to retrieve all key-value pairs with the
* requested character.
*/
static boost::function<bool(Key)> ChrTest(unsigned char c);
static std::function<bool(Key)> ChrTest(unsigned char c);

/// Output stream operator that can be used with key_formatter (see Key.h).
GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const Symbol &);
Expand Down
4 changes: 2 additions & 2 deletions gtsam/linear/VectorValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace gtsam {
{
// Merge using predicate for comparing first of pair
merge(first.begin(), first.end(), second.begin(), second.end(), inserter(values_, values_.end()),
boost::bind(&less<Key>::operator(), less<Key>(), boost::bind(&KeyValuePair::first, boost::placeholders::_1),
boost::bind(&KeyValuePair::first, boost::placeholders::_2)));
std::bind(&less<Key>::operator(), less<Key>(), std::bind(&KeyValuePair::first, std::placeholders::_1),
std::bind(&KeyValuePair::first, std::placeholders::_2)));
if(size() != first.size() + second.size())
throw invalid_argument("Requested to merge two VectorValues that have one or more variables in common.");
}
Expand Down
24 changes: 12 additions & 12 deletions gtsam/nonlinear/Expression-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ template<typename A>
Expression<T>::Expression(const Expression<A>& expression,
T (A::*method)(typename MakeOptionalJacobian<T, A>::type) const) :
root_(
new internal::UnaryExpression<T, A>(boost::bind(method,
boost::placeholders::_1, boost::placeholders::_2),
new internal::UnaryExpression<T, A>(std::bind(method,
std::placeholders::_1, std::placeholders::_2),
expression)) {
}

Expand All @@ -97,9 +97,9 @@ Expression<T>::Expression(const Expression<A1>& expression1,
const Expression<A2>& expression2) :
root_(
new internal::BinaryExpression<T, A1, A2>(
boost::bind(method, boost::placeholders::_1,
boost::placeholders::_2, boost::placeholders::_3,
boost::placeholders::_4),
std::bind(method, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4),
expression1, expression2)) {
}

Expand All @@ -114,10 +114,10 @@ Expression<T>::Expression(const Expression<A1>& expression1,
const Expression<A2>& expression2, const Expression<A3>& expression3) :
root_(
new internal::TernaryExpression<T, A1, A2, A3>(
boost::bind(method, boost::placeholders::_1,
boost::placeholders::_2, boost::placeholders::_3,
boost::placeholders::_4, boost::placeholders::_5,
boost::placeholders::_6),
std::bind(method, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, std::placeholders::_5,
std::placeholders::_6),
expression1, expression2, expression3)) {
}

Expand Down Expand Up @@ -255,9 +255,9 @@ template<typename T>
Expression<T> operator*(const Expression<T>& expression1,
const Expression<T>& expression2) {
return Expression<T>(
boost::bind(internal::apply_compose<T>(), boost::placeholders::_1,
boost::placeholders::_2, boost::placeholders::_3,
boost::placeholders::_4),
std::bind(internal::apply_compose<T>(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4),
expression1, expression2);
}

Expand Down
8 changes: 4 additions & 4 deletions gtsam/nonlinear/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ class Expression {
// Expression<Point2>::BinaryFunction<PinholeCamera<Cal3_S2>,Point3>::type
template<class A1>
struct UnaryFunction {
typedef boost::function<
typedef std::function<
T(const A1&, typename MakeOptionalJacobian<T, A1>::type)> type;
};

template<class A1, class A2>
struct BinaryFunction {
typedef boost::function<
typedef std::function<
T(const A1&, const A2&, typename MakeOptionalJacobian<T, A1>::type,
typename MakeOptionalJacobian<T, A2>::type)> type;
};

template<class A1, class A2, class A3>
struct TernaryFunction {
typedef boost::function<
typedef std::function<
T(const A1&, const A2&, const A3&,
typename MakeOptionalJacobian<T, A1>::type,
typename MakeOptionalJacobian<T, A2>::type,
Expand Down Expand Up @@ -239,7 +239,7 @@ class BinarySumExpression : public Expression<T> {
*/
template <typename T, typename A>
Expression<T> linearExpression(
const boost::function<T(A)>& f, const Expression<A>& expression,
const std::function<T(A)>& f, const Expression<A>& expression,
const Eigen::Matrix<double, traits<T>::dimension, traits<A>::dimension>& dTdA) {
// Use lambda to endow f with a linear Jacobian
typename Expression<T>::template UnaryFunction<A>::type g =
Expand Down
10 changes: 5 additions & 5 deletions gtsam/nonlinear/NonlinearEquality.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NonlinearEquality: public NoiseModelFactor1<VALUE> {
/**
* Function that compares two values
*/
typedef boost::function<bool(const T&, const T&)> CompareFunction;
typedef std::function<bool(const T&, const T&)> CompareFunction;
CompareFunction compare_;
// bool (*compare_)(const T& a, const T& b);

Expand All @@ -87,8 +87,8 @@ class NonlinearEquality: public NoiseModelFactor1<VALUE> {
* Constructor - forces exact evaluation
*/
NonlinearEquality(Key j, const T& feasible,
const CompareFunction &_compare = boost::bind(traits<T>::Equals,
boost::placeholders::_1, boost::placeholders::_2, 1e-9)) :
const CompareFunction &_compare = std::bind(traits<T>::Equals,
std::placeholders::_1, std::placeholders::_2, 1e-9)) :
Base(noiseModel::Constrained::All(traits<T>::GetDimension(feasible)),
j), feasible_(feasible), allow_error_(false), error_gain_(0.0), //
compare_(_compare) {
Expand All @@ -98,8 +98,8 @@ class NonlinearEquality: public NoiseModelFactor1<VALUE> {
* Constructor - allows inexact evaluation
*/
NonlinearEquality(Key j, const T& feasible, double error_gain,
const CompareFunction &_compare = boost::bind(traits<T>::Equals,
boost::placeholders::_1, boost::placeholders::_2, 1e-9)) :
const CompareFunction &_compare = std::bind(traits<T>::Equals,
std::placeholders::_1, std::placeholders::_2, 1e-9)) :
Base(noiseModel::Constrained::All(traits<T>::GetDimension(feasible)),
j), feasible_(feasible), allow_error_(true), error_gain_(error_gain), //
compare_(_compare) {
Expand Down
Loading

0 comments on commit dc8b5e5

Please sign in to comment.