IAP GITLAB

Skip to content
Snippets Groups Projects
Commit c58cf76c authored by ralfulrich's avatar ralfulrich
Browse files

fix warnings

parent 0649f830
No related branches found
No related tags found
No related merge requests found
...@@ -29,238 +29,290 @@ ...@@ -29,238 +29,290 @@
namespace random_iterator_tbb { namespace random_iterator_tbb {
template <typename Type>
class constant_iterator {
template <typename Type> public:
class constant_iterator {
public:
typedef typename std::size_t difference_type; typedef typename std::size_t difference_type;
typedef Type value_type; typedef Type value_type;
typedef const Type* pointer; typedef const Type* pointer;
typedef const Type& reference; typedef const Type& reference;
typedef std::random_access_iterator_tag iterator_category; typedef std::random_access_iterator_tag iterator_category;
constant_iterator() : my_value() {} constant_iterator()
explicit constant_iterator(Type init) : my_value(init) {} : my_value() {}
explicit constant_iterator(Type init)
: my_value(init) {}
inline reference operator*() const { return my_value; } inline reference operator*() const { return my_value; }
inline value_type operator[](difference_type i) const { return my_value; } inline value_type operator[](difference_type) const { return my_value; }
inline difference_type operator-(const constant_iterator<Type>& it) const { return 0; } inline difference_type operator-(const constant_iterator<Type>&) const { return 0; }
inline constant_iterator<Type>& operator+=(difference_type forward) const { return *this; } inline constant_iterator<Type>& operator+=(difference_type) const { return *this; }
inline constant_iterator<Type>& operator-=(difference_type backward) const { return *this; } inline constant_iterator<Type>& operator-=(difference_type) const { return *this; }
inline constant_iterator<Type>& operator++() const { return *this; } inline constant_iterator<Type>& operator++() const { return *this; }
inline constant_iterator<Type>& operator--() const { return *this; } inline constant_iterator<Type>& operator--() const { return *this; }
inline constant_iterator<Type> operator++(int) { return constant_iterator<Type>(my_value); } inline constant_iterator<Type> operator++(int) {
return constant_iterator<Type>(my_value);
inline constant_iterator<Type> operator--(int) { return constant_iterator<Type>(my_value); } }
inline constant_iterator<Type> operator-(difference_type backward) const { return constant_iterator<Type>(my_value); }
inline constant_iterator<Type> operator+(difference_type forward) const { return constant_iterator<Type>(my_value); }
friend constant_iterator<Type> operator+(difference_type forward, const constant_iterator<Type> it) { return constant_iterator<Type>(*it); }
inline bool operator==(const constant_iterator<Type>& it) const { return (my_value - *it) == 0; }
inline bool operator!=(const constant_iterator<Type>& it) const { return !(my_value == *it); }
private: inline constant_iterator<Type> operator--(int) {
const value_type my_value; return constant_iterator<Type>(my_value);
}; }
inline constant_iterator<Type> operator-(difference_type) const {
return constant_iterator<Type>(my_value);
}
inline constant_iterator<Type> operator+(difference_type) const {
return constant_iterator<Type>(my_value);
}
friend constant_iterator<Type> operator+(difference_type,
const constant_iterator<Type> it) {
return constant_iterator<Type>(*it);
}
template <typename IntType> inline bool operator==(const constant_iterator<Type>& it) const {
class counting_iterator { return (my_value - *it) == 0;
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer, "Cannot instantiate counting_iterator with a non-integer type"); }
public: inline bool operator!=(const constant_iterator<Type>& it) const {
typedef typename std::make_signed<IntType>::type difference_type; return !(my_value == *it);
typedef IntType value_type; }
typedef const IntType* pointer;
typedef const IntType& reference;
typedef std::random_access_iterator_tag iterator_category;
counting_iterator() : my_counter() {} private:
explicit counting_iterator(IntType init) : my_counter(init) {} const value_type my_value;
};
template <typename IntType>
class counting_iterator {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(
std::numeric_limits<IntType>::is_integer,
"Cannot instantiate counting_iterator with a non-integer type");
public:
typedef typename std::make_signed<IntType>::type difference_type;
typedef IntType value_type;
typedef const IntType* pointer;
typedef const IntType& reference;
typedef std::random_access_iterator_tag iterator_category;
inline reference operator*() const { return my_counter; } counting_iterator()
inline value_type operator[](difference_type i) const { return *(*this + i); } : my_counter() {}
explicit counting_iterator(IntType init)
: my_counter(init) {}
inline difference_type operator-(const counting_iterator& it) const { return my_counter - it.my_counter; } inline reference operator*() const { return my_counter; }
inline value_type operator[](difference_type i) const { return *(*this + i); }
inline counting_iterator& operator+=(difference_type forward) { my_counter += forward; return *this; } inline difference_type operator-(const counting_iterator& it) const {
inline counting_iterator& operator-=(difference_type backward) { return *this += -backward; } return my_counter - it.my_counter;
inline counting_iterator& operator++() { return *this += 1; } }
inline counting_iterator& operator--() { return *this -= 1; }
inline counting_iterator operator++(int) { inline counting_iterator& operator+=(difference_type forward) {
counting_iterator it(*this); my_counter += forward;
++(*this); return *this;
return it; }
} inline counting_iterator& operator-=(difference_type backward) {
inline counting_iterator operator--(int) { return *this += -backward;
counting_iterator it(*this); }
--(*this); inline counting_iterator& operator++() { return *this += 1; }
return it; inline counting_iterator& operator--() { return *this -= 1; }
}
inline counting_iterator operator-(difference_type backward) const { return counting_iterator(my_counter - backward); } inline counting_iterator operator++(int) {
inline counting_iterator operator+(difference_type forward) const { return counting_iterator(my_counter + forward); } counting_iterator it(*this);
friend counting_iterator operator+(difference_type forward, const counting_iterator it) { return it + forward; } ++(*this);
return it;
}
inline counting_iterator operator--(int) {
counting_iterator it(*this);
--(*this);
return it;
}
inline bool operator==(const counting_iterator& it) const { return *this - it == 0; } inline counting_iterator operator-(difference_type backward) const {
inline bool operator!=(const counting_iterator& it) const { return !(*this == it); } return counting_iterator(my_counter - backward);
inline bool operator<(const counting_iterator& it) const {return *this - it < 0; } }
inline bool operator>(const counting_iterator& it) const { return it < *this; } inline counting_iterator operator+(difference_type forward) const {
inline bool operator<=(const counting_iterator& it) const { return !(*this > it); } return counting_iterator(my_counter + forward);
inline bool operator>=(const counting_iterator& it) const { return !(*this < it); } }
friend counting_iterator operator+(difference_type forward,
const counting_iterator it) {
return it + forward;
}
private: inline bool operator==(const counting_iterator& it) const { return *this - it == 0; }
IntType my_counter; inline bool operator!=(const counting_iterator& it) const { return !(*this == it); }
}; inline bool operator<(const counting_iterator& it) const { return *this - it < 0; }
} //namespace random_iterator_tbb inline bool operator>(const counting_iterator& it) const { return it < *this; }
inline bool operator<=(const counting_iterator& it) const { return !(*this > it); }
inline bool operator>=(const counting_iterator& it) const { return !(*this < it); }
private:
IntType my_counter;
};
} // namespace random_iterator_tbb
#include <tuple> #include <tuple>
#include "internal/_template_helpers.h" // index_sequence, make_index_sequence #include "internal/_template_helpers.h" // index_sequence, make_index_sequence
namespace random_iterator_tbb { namespace random_iterator_tbb {
namespace internal { namespace internal {
template<size_t N> template <size_t N>
struct tuple_util { struct tuple_util {
template<typename TupleType, typename DifferenceType> template <typename TupleType, typename DifferenceType>
static void increment(TupleType& it, DifferenceType forward) { static void increment(TupleType& it, DifferenceType forward) {
std::get<N-1>(it) += forward; std::get<N - 1>(it) += forward;
tuple_util<N-1>::increment(it, forward); tuple_util<N - 1>::increment(it, forward);
} }
template<typename TupleType, typename DifferenceType> template <typename TupleType, typename DifferenceType>
static bool check_sync(const TupleType& it1, const TupleType& it2, DifferenceType val) { static bool check_sync(const TupleType& it1, const TupleType& it2,
if(std::get<N-1>(it1) - std::get<N-1>(it2) != val) DifferenceType val) {
return false; if (std::get<N - 1>(it1) - std::get<N - 1>(it2) != val) return false;
return tuple_util<N-1>::check_sync(it1, it2, val); return tuple_util<N - 1>::check_sync(it1, it2, val);
} }
}; };
template<> template <>
struct tuple_util<0> { struct tuple_util<0> {
template<typename TupleType, typename DifferenceType> template <typename TupleType, typename DifferenceType>
static void increment(TupleType&, DifferenceType) {} static void increment(TupleType&, DifferenceType) {}
template<typename TupleType, typename DifferenceType> template <typename TupleType, typename DifferenceType>
static bool check_sync(const TupleType&, const TupleType&, DifferenceType) { return true;} static bool check_sync(const TupleType&, const TupleType&, DifferenceType) {
}; return true;
}
template <typename TupleReturnType> };
struct make_references {
template <typename TupleType, std::size_t... Is> template <typename TupleReturnType>
TupleReturnType operator()(const TupleType& t, random_iterator_tbb::internal::index_sequence<Is...>) { struct make_references {
return std::tie( *std::get<Is>(t)... ); template <typename TupleType, std::size_t... Is>
} TupleReturnType operator()(const TupleType& t,
}; random_iterator_tbb::internal::index_sequence<Is...>) {
return std::tie(*std::get<Is>(t)...);
// A simple wrapper over a tuple of references. }
// The class is designed to hold a temporary tuple of reference };
// after dereferencing a zip_iterator; in particular, it is needed
// to swap these rvalue tuples. Any other usage is not supported. // A simple wrapper over a tuple of references.
template<typename... T> // The class is designed to hold a temporary tuple of reference
struct tuplewrapper : public std::tuple<typename std::enable_if<std::is_reference<T>::value, T&&>::type...> { // after dereferencing a zip_iterator; in particular, it is needed
// In the context of this class, T is a reference, so T&& is a "forwarding reference" // to swap these rvalue tuples. Any other usage is not supported.
typedef std::tuple<T&&...> base_type; template <typename... T>
// Construct from the result of std::tie struct tuplewrapper
tuplewrapper(const base_type& in) : base_type(in) {} : public std::tuple<
typename std::enable_if<std::is_reference<T>::value, T&&>::type...> {
// In the context of this class, T is a reference, so T&& is a "forwarding
// reference"
typedef std::tuple<T&&...> base_type;
// Construct from the result of std::tie
tuplewrapper(const base_type& in)
: base_type(in) {}
#if __INTEL_COMPILER #if __INTEL_COMPILER
// ICC cannot generate copy ctor & assignment // ICC cannot generate copy ctor & assignment
tuplewrapper(const tuplewrapper& rhs) : base_type(rhs) {} tuplewrapper(const tuplewrapper& rhs)
tuplewrapper& operator=(const tuplewrapper& rhs) { : base_type(rhs) {}
tuplewrapper& operator=(const tuplewrapper& rhs) {
*this = base_type(rhs); *this = base_type(rhs);
return *this; return *this;
} }
#endif #endif
// Assign any tuple convertible to std::tuple<T&&...>: *it = a_tuple; // Assign any tuple convertible to std::tuple<T&&...>: *it = a_tuple;
template<typename... U> template <typename... U>
tuplewrapper& operator=(const std::tuple<U...>& other) { tuplewrapper& operator=(const std::tuple<U...>& other) {
base_type::operator=(other); base_type::operator=(other);
return *this; return *this;
} }
#if _LIBCPP_VERSION #if _LIBCPP_VERSION
// (Necessary for libc++ tuples) Convert to a tuple of values: v = *it; // (Necessary for libc++ tuples) Convert to a tuple of values: v = *it;
operator std::tuple<typename std::remove_reference<T>::type...>() { return base_type(*this); } operator std::tuple<typename std::remove_reference<T>::type...>() {
return base_type(*this);
}
#endif #endif
// Swap rvalue tuples: swap(*it1,*it2); // Swap rvalue tuples: swap(*it1,*it2);
friend void swap(tuplewrapper&& a, tuplewrapper&& b) { friend void swap(tuplewrapper&& a, tuplewrapper&& b) { std::swap<T&&...>(a, b); }
std::swap<T&&...>(a,b); };
}
};
} //namespace internal } // namespace internal
template <typename... Types> template <typename... Types>
class zip_iterator { class zip_iterator {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(sizeof...(Types)>0, "Cannot instantiate zip_iterator with empty template parameter pack"); __RANDOM_ITERATOR_TBB_STATIC_ASSERT(
sizeof...(Types) > 0,
"Cannot instantiate zip_iterator with empty template parameter pack");
static const std::size_t num_types = sizeof...(Types); static const std::size_t num_types = sizeof...(Types);
typedef std::tuple<Types...> it_types; typedef std::tuple<Types...> it_types;
public:
public:
typedef typename std::make_signed<std::size_t>::type difference_type; typedef typename std::make_signed<std::size_t>::type difference_type;
typedef std::tuple<typename std::iterator_traits<Types>::value_type...> value_type; typedef std::tuple<typename std::iterator_traits<Types>::value_type...> value_type;
#if __INTEL_COMPILER && __INTEL_COMPILER < 1800 && _MSC_VER #if __INTEL_COMPILER && __INTEL_COMPILER < 1800 && _MSC_VER
typedef std::tuple<typename std::iterator_traits<Types>::reference...> reference; typedef std::tuple<typename std::iterator_traits<Types>::reference...> reference;
#else #else
typedef random_iterator_tbb::internal::tuplewrapper<typename std::iterator_traits<Types>::reference...> reference; typedef random_iterator_tbb::internal::tuplewrapper<
typename std::iterator_traits<Types>::reference...>
reference;
#endif #endif
typedef std::tuple<typename std::iterator_traits<Types>::pointer...> pointer; typedef std::tuple<typename std::iterator_traits<Types>::pointer...> pointer;
typedef std::random_access_iterator_tag iterator_category; typedef std::random_access_iterator_tag iterator_category;
zip_iterator() : my_it() {} zip_iterator()
explicit zip_iterator(Types... args) : my_it(std::make_tuple(args...)) {} : my_it() {}
zip_iterator(const zip_iterator& input) : my_it(input.my_it) {} explicit zip_iterator(Types... args)
: my_it(std::make_tuple(args...)) {}
zip_iterator(const zip_iterator& input)
: my_it(input.my_it) {}
zip_iterator& operator=(const zip_iterator& input) { zip_iterator& operator=(const zip_iterator& input) {
my_it = input.my_it; my_it = input.my_it;
return *this; return *this;
} }
reference operator*() const { reference operator*() const {
return random_iterator_tbb::internal::make_references<reference>()(my_it, random_iterator_tbb::internal::make_index_sequence<num_types>()); return random_iterator_tbb::internal::make_references<reference>()(
my_it, random_iterator_tbb::internal::make_index_sequence<num_types>());
} }
reference operator[](difference_type i) const { return *(*this + i); } reference operator[](difference_type i) const { return *(*this + i); }
difference_type operator-(const zip_iterator& it) const { difference_type operator-(const zip_iterator& it) const {
__RANDOM_ITERATOR_TBB_ASSERT(internal::tuple_util<num_types>::check_sync(my_it, it.my_it, std::get<0>(my_it) - std::get<0>(it.my_it)), __RANDOM_ITERATOR_TBB_ASSERT(
"Components of zip_iterator are not synchronous"); internal::tuple_util<num_types>::check_sync(
return std::get<0>(my_it) - std::get<0>(it.my_it); my_it, it.my_it, std::get<0>(my_it) - std::get<0>(it.my_it)),
"Components of zip_iterator are not synchronous");
return std::get<0>(my_it) - std::get<0>(it.my_it);
} }
zip_iterator& operator+=(difference_type forward) { zip_iterator& operator+=(difference_type forward) {
internal::tuple_util<num_types>::increment(my_it, forward); internal::tuple_util<num_types>::increment(my_it, forward);
return *this; return *this;
} }
zip_iterator& operator-=(difference_type backward) { return *this += -backward; } zip_iterator& operator-=(difference_type backward) { return *this += -backward; }
zip_iterator& operator++() { return *this += 1; } zip_iterator& operator++() { return *this += 1; }
zip_iterator& operator--() { return *this -= 1; } zip_iterator& operator--() { return *this -= 1; }
zip_iterator operator++(int) { zip_iterator operator++(int) {
zip_iterator it(*this); zip_iterator it(*this);
++(*this); ++(*this);
return it; return it;
} }
zip_iterator operator--(int) { zip_iterator operator--(int) {
zip_iterator it(*this); zip_iterator it(*this);
--(*this); --(*this);
return it; return it;
} }
zip_iterator operator-(difference_type backward) const { zip_iterator operator-(difference_type backward) const {
zip_iterator it(*this); zip_iterator it(*this);
return it -= backward; return it -= backward;
} }
zip_iterator operator+(difference_type forward) const { zip_iterator operator+(difference_type forward) const {
zip_iterator it(*this); zip_iterator it(*this);
return it += forward; return it += forward;
} }
friend zip_iterator operator+(difference_type forward, const zip_iterator& it) { return it + forward; } friend zip_iterator operator+(difference_type forward, const zip_iterator& it) {
return it + forward;
bool operator==(const zip_iterator& it) const {
return *this - it == 0;
} }
bool operator==(const zip_iterator& it) const { return *this - it == 0; }
it_types base() const { return my_it; } it_types base() const { return my_it; }
bool operator!=(const zip_iterator& it) const { return !(*this == it); } bool operator!=(const zip_iterator& it) const { return !(*this == it); }
...@@ -268,78 +320,86 @@ public: ...@@ -268,78 +320,86 @@ public:
bool operator>(const zip_iterator& it) const { return it < *this; } bool operator>(const zip_iterator& it) const { return it < *this; }
bool operator<=(const zip_iterator& it) const { return !(*this > it); } bool operator<=(const zip_iterator& it) const { return !(*this > it); }
bool operator>=(const zip_iterator& it) const { return !(*this < it); } bool operator>=(const zip_iterator& it) const { return !(*this < it); }
private:
private:
it_types my_it; it_types my_it;
}; };
template<typename... T> template <typename... T>
zip_iterator<T...> make_zip_iterator(T... args) { return zip_iterator<T...>(args...); } zip_iterator<T...> make_zip_iterator(T... args) {
return zip_iterator<T...>(args...);
}
template <typename UnaryFunc, typename Iter> template <typename UnaryFunc, typename Iter>
class transform_iterator { class transform_iterator {
public: public:
typedef typename std::iterator_traits<Iter>::value_type value_type; typedef typename std::iterator_traits<Iter>::value_type value_type;
typedef typename std::iterator_traits<Iter>::difference_type difference_type; typedef typename std::iterator_traits<Iter>::difference_type difference_type;
#if __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT #if __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT
typedef typename std::invoke_result<UnaryFunc, typename std::iterator_traits<Iter>::reference>::type reference; typedef typename std::invoke_result<
UnaryFunc, typename std::iterator_traits<Iter>::reference>::type reference;
#else #else
typedef typename std::result_of<UnaryFunc(typename std::iterator_traits<Iter>::reference)>::type reference; typedef typename std::result_of<UnaryFunc(
typename std::iterator_traits<Iter>::reference)>::type reference;
#endif #endif
typedef typename std::iterator_traits<Iter>::pointer pointer; typedef typename std::iterator_traits<Iter>::pointer pointer;
typedef typename std::random_access_iterator_tag iterator_category; typedef typename std::random_access_iterator_tag iterator_category;
transform_iterator(Iter it, UnaryFunc unary_func) : my_it(it), my_unary_func(unary_func) { transform_iterator(Iter it, UnaryFunc unary_func)
__RANDOM_ITERATOR_TBB_STATIC_ASSERT((std::is_same<typename std::iterator_traits<Iter>::iterator_category, : my_it(it)
std::random_access_iterator_tag>::value), "Random access iterator required."); , my_unary_func(unary_func) {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(
(std::is_same<typename std::iterator_traits<Iter>::iterator_category,
std::random_access_iterator_tag>::value),
"Random access iterator required.");
} }
transform_iterator(const transform_iterator& input) : my_it(input.my_it), my_unary_func(input.my_unary_func) { } transform_iterator(const transform_iterator& input)
: my_it(input.my_it)
, my_unary_func(input.my_unary_func) {}
transform_iterator& operator=(const transform_iterator& input) { transform_iterator& operator=(const transform_iterator& input) {
my_it = input.my_it; my_it = input.my_it;
return *this; return *this;
}
reference operator*() const {
return my_unary_func(*my_it);
}
reference operator[](difference_type i) const {
return *(*this + i);
} }
reference operator*() const { return my_unary_func(*my_it); }
reference operator[](difference_type i) const { return *(*this + i); }
transform_iterator& operator++() { transform_iterator& operator++() {
++my_it; ++my_it;
return *this; return *this;
} }
transform_iterator& operator--() { transform_iterator& operator--() {
--my_it; --my_it;
return *this; return *this;
} }
transform_iterator operator++(int) { transform_iterator operator++(int) {
transform_iterator it(*this); transform_iterator it(*this);
++(*this); ++(*this);
return it; return it;
} }
transform_iterator operator--(int) { transform_iterator operator--(int) {
transform_iterator it(*this); transform_iterator it(*this);
--(*this); --(*this);
return it; return it;
} }
transform_iterator operator+(difference_type forward) const { transform_iterator operator+(difference_type forward) const {
return { my_it + forward, my_unary_func }; return {my_it + forward, my_unary_func};
} }
transform_iterator operator-(difference_type backward) const { transform_iterator operator-(difference_type backward) const {
return { my_it - backward, my_unary_func }; return {my_it - backward, my_unary_func};
} }
transform_iterator& operator+=(difference_type forward) { transform_iterator& operator+=(difference_type forward) {
my_it += forward; my_it += forward;
return *this; return *this;
} }
transform_iterator& operator-=(difference_type backward) { transform_iterator& operator-=(difference_type backward) {
my_it -= backward; my_it -= backward;
return *this; return *this;
} }
friend transform_iterator operator+(difference_type forward, const transform_iterator& it) { friend transform_iterator operator+(difference_type forward,
return it + forward; const transform_iterator& it) {
return it + forward;
} }
difference_type operator-(const transform_iterator& it) const { difference_type operator-(const transform_iterator& it) const {
return my_it - it.my_it; return my_it - it.my_it;
} }
bool operator==(const transform_iterator& it) const { return *this - it == 0; } bool operator==(const transform_iterator& it) const { return *this - it == 0; }
bool operator!=(const transform_iterator& it) const { return !(*this == it); } bool operator!=(const transform_iterator& it) const { return !(*this == it); }
...@@ -349,17 +409,19 @@ public: ...@@ -349,17 +409,19 @@ public:
bool operator>=(const transform_iterator& it) const { return !(*this < it); } bool operator>=(const transform_iterator& it) const { return !(*this < it); }
Iter base() const { return my_it; } Iter base() const { return my_it; }
private:
private:
Iter my_it; Iter my_it;
const UnaryFunc my_unary_func; const UnaryFunc my_unary_func;
}; };
template<typename UnaryFunc, typename Iter> template <typename UnaryFunc, typename Iter>
transform_iterator<UnaryFunc, Iter> make_transform_iterator(Iter it, UnaryFunc unary_func) { transform_iterator<UnaryFunc, Iter> make_transform_iterator(Iter it,
UnaryFunc unary_func) {
return transform_iterator<UnaryFunc, Iter>(it, unary_func); return transform_iterator<UnaryFunc, Iter>(it, unary_func);
} }
} //namespace random_iterator_tbb } // namespace random_iterator_tbb
#endif //__RANDOM_ITERATOR_TBB_CPP11_PRESENT #endif //__RANDOM_ITERATOR_TBB_CPP11_PRESENT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment