|
Boost Users : |
Subject: Re: [Boost-users] boost::range RangeConcept problem.
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-01-16 22:25:33
On Tue, Jan 15, 2013 at 10:26 AM, Hurcan Solter <hsolter_at_[hidden]> wrote:
>
> The following snippet is the mock-up of the problem I am having in order
> to be able to reproduce.
>
>
> --------------------------------------------------------------------------------
> #include <iostream>
> #include <boost/range.hpp>
> #include <boost/range/adaptors.hpp>
> #include <boost/range/algorithm.hpp>
> #include <boost/bind.hpp>
> #include <boost/assign.hpp>
>
>
> using namespace boost::assign;
> struct wxSize
> {
> wxSize(int height=0,int width=0):m_height(height),m_width(width)
> { }
> int GetWidth() const {return m_width;}
> int m_height;
> int m_width;
> };
> class wxWindowBase
> {
> public:
> wxSize GetTextExtent(const std::string val)
> {
> return wxSize(0,val.length());
> }
> void DoLayout(std::vector<std::string> m_FilteredItems)
> {
>
> using boost::adaptors::transformed;
> wxSize longest = *boost::max_element(m_FilteredItems |
> transformed(boost::bind(&wxWindowBase::GetTextExtent,this,_1)),
>
> boost::bind(std::less<int>(),boost::bind(&wxSize::GetWidth,_1),boost::bind(&wxSize::GetWidth,_2)));
>
> std::cout <<longest.GetWidth();
> }
> };
> int main()
> {
> std::vector<std::string> input;
> input += "o","two","threexxx","four";
> wxWindowBase window;
> window.DoLayout(input);
> }
>
> -----------------------------------------------------------------------------------------
> The above code fails to compile on GCC4.7.2 and MSVC10 although
> it compiles and runs fine on clang3.3
>
> From what I understand ,transformed returns a Single Pass Range and
> max_element expects a ForwardRange
> and that's the gist of the problem.But it works for something like
>
> max_element(someint_vector |
> transformed(doubleit()),std::less<int>()); without problems.
>
> Is there a elegant way to achieve what I am trying to without using a
> intermediate container?
> Thanks in advance..
>
I would try simplifying things (e.g., replace the uses of bind with
explicit function objects; define an operator< for wxSize), then if you're
still lost, paste the error (I don't have immediate access to MSVC 10 or
gcc 4.7).
- Jeff
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net