Subject: [Boost-bugs] [Boost C++ Libraries] #9515: [range] uniqued adaptor (and hence adjacent_filtered) returns wrong elements
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-20 22:10:53
#9515: [range] uniqued adaptor (and hence adjacent_filtered) returns wrong
elements
------------------------------+---------------------
Reporter: eric_niebler | Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: Boost 1.54.0 | Severity: Problem
Keywords: |
------------------------------+---------------------
The following shows the difference between the `boost::range::unique_copy`
algorithm and the `boost::adaptors::unique` adaptor.
{{{
#include <string>
#include <vector>
#include <iterator>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/range/algorithm/unique_copy.hpp>
#include <boost/range/adaptor/uniqued.hpp>
struct istring
{
char const *c_str;
istring(char const *s) : c_str(s) {}
bool operator==(istring u) const
{
return boost::iequals(c_str, u.c_str);
}
friend std::ostream& operator<<(std::ostream& sout, istring s)
{
return sout << s.c_str;
}
};
int main()
{
std::vector<istring> strs;
strs.push_back(istring("hello"));
strs.push_back(istring("HELLO"));
std::cout << "boost.range: \n";
boost::range::copy(
boost::adaptors::unique(strs),
std::ostream_iterator<istring>(std::cout));
std::cout << "\n";
std::cout << "std algo: \n";
boost::range::unique_copy(strs,
std::ostream_iterator<istring>(std::cout));
std::cout << "\n";
}
}}}
This prints:
{{{
boost.range:
HELLO
std algo:
hello
}}}
`std::unique` and `std::unique_copy` yield the *first* element in a
sequence of equivalent elements. The Boost adaptor yields the last. This
is an important and observable difference.
Since `uniqued` is implemented in terms of `adjacent_filtered`, the
problem needs to be fixed there.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9515> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC