◆ lexicographical_compare() [2/2]

template<typename T , typename Pred >
bool boost::simd::lexicographical_compare ( T const *  first1,
T const *  last1,
T const *  first2,
T const *  last2,
Pred  comp 

Returns true if the range [first1, last1) is lexicographically less than the second range [first2, first2 + (last1 - first1)), and false otherwise using comp as elementwise comparison.

first1,last1- the first range of the elements to compare
first2,last2- the second range of the elements to compare
comp- binary predicate operation function object that will be applied.
  • first, last and out must be pointer to Vectorizable type.
  • comp must be a polymorphic binary function object, i.e callable on generic types.
  • Two ranges are compared element by element.
  • The first mismatching element defines which range is lexicographically less or greater than the other.
  • If one range is a prefix of another, the shorter range is lexicographically less than the other.
  • If two ranges have equivalent elements and are of the same length, then the ranges are lexicographically equal.
  • An empty range is lexicographically less than any non-empty range.
  • Two empty ranges are lexicographically equal.
#include <boost/simd/algorithm/lexicographical_compare.hpp>
#include <boost/simd/function/inc.hpp>
#include <iostream>
#include <vector>
int main()
std::vector<float> c{1.f, 2.f, 2.f, 3.f, 4.f, 5.f, 6.f};
std::vector<float> d{1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f};
bool b1 = boost::simd::lexicographical_compare( d.data(), d.data()+7, d.data(), d.data()+7);
bool b2 = boost::simd::lexicographical_compare( c.data(), c.data()+7, d.data(), d.data()+7);
bool b3 = boost::simd::lexicographical_compare( c.data(), c.data()+7, c.data(), c.data()+5);
bool b4 = boost::simd::lexicographical_compare( d.data(), d.data()+7, c.data(), c.data()+5);
bool b5 = boost::simd::lexicographical_compare( c.data(), c.data()+5, c.data(), c.data()+7);
std::cout << "b1 " << b1 << '\n';
std::cout << "b2 " << b2 << '\n';
std::cout << "b3 " << b3 << '\n';
std::cout << "b4 " << b4 << '\n';
std::cout << "b5 " << b5 << '\n';
return 0;
Possible output:
b1 0
b2 1
b3 0
b4 0
b5 1