Skip to content

Commit

Permalink
Reducing boost usage with assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaltyagi committed Feb 6, 2020
1 parent f2568a5 commit 1baadca
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions common/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
#include <pcl/console/print.h>

#include <boost/algorithm/string.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/vector.hpp>

////////////////////////////////////////////////////////////////////////////////
int
Expand Down Expand Up @@ -129,6 +126,19 @@ parse_argument (int argc, const char * const * argv, const char * str, long long
return parse_generic(strtoll_10, argc, argv, str, val);
}

int
parse_argument (int argc, const char * const * argv, const char * str, unsigned long long int &val) noexcept
{
long long int dummy;
const auto ret = parse_argument (argc, argv, str, dummy);
if ((ret == -1) || dummy < 0)
{
return -1;
}
val = dummy;
return ret;
}

namespace detail
{
template <typename T, typename U>
Expand All @@ -139,18 +149,19 @@ struct legally_representable {
constexpr static bool value = legally_representable_v<T, U>;
};

using input_types = boost::mpl::vector<long int, long long int>;

template <typename Integral>
using legal_input_type_iter = typename boost::mpl::find_if<input_types,
legally_representable<boost::mpl::_1, Integral>>::type;
// assumptions:
// * either long int or long long int is a valid type for storing Integral
// * unsigned long long int is handled specially
template <typename Integral>
using legal_input_type = typename boost::mpl::deref<legal_input_type_iter<Integral>>::type;
using legal_input_type = std::conditional_t<legally_representable_v<long int, Integral>,
long int, long long int>;

static_assert ((std::is_same<legal_input_type<int>, long int>::value) ||
(std::is_same<legal_input_type<int>, long long int>::value));
(std::is_same<legal_input_type<int>, long long int>::value),
"Either long int or long long int need to satisfy the condition");
static_assert ((std::is_same<legal_input_type<unsigned int>, long int>::value) ||
(std::is_same<legal_input_type<unsigned int>, long long int>::value));
(std::is_same<legal_input_type<unsigned int>, long long int>::value),
"Either long int or long long int need to satisfy the condition");
}

template <typename T>
Expand Down

0 comments on commit 1baadca

Please sign in to comment.