Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::range RangeConcept problem.
From: Hurcan Solter (hsolter_at_[hidden])
Date: 2013-01-17 12:24:54


On Thu, Jan 17, 2013 at 5:25 AM, Jeffrey Lee Hellrung, Jr. <
jeffrey.hellrung_at_[hidden]> wrote:

> 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
>
> I am pretty convinced that Akira has nailed it. The problem was in the
> first line and in any case it does not make sense defining operator < for
> size objects unless you are comparing areas and as for functors I've used
> bind exclusively to avoid writing them (hence the std::less) .
>
   Seeing that it compiles fine on clang I've disabled concept checks by
defining BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0 .
   Apparently clang bypasses concept check or maybe it's disabled for that
particular compiler (Is it?) . It works fine on both MSVC and gcc now.
Although I might be shooting
  myself in the foot

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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