This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stl_vector.h ::resize in llvm gcc4.2


Indeed a very nice trick.

I prefer to declare a member function pointer, which simplifies the
following expression. For example:

set<int>::size_type (set<int>::*set_erase)(const set<int>::key_type&)
= &set<int>::erase;

for_each(x.begin(), x.end(), boost::bind(set_erase, container, _1));

Regards.

On Wed, Feb 29, 2012 at 6:58 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 29 February 2012 17:51, Daniel Stoltmann wrote:
>>
>> in gcc4.0 the following code compiled fine:
>>
>> std::vector< std::vector<myData> >      mMy;
>>
>> std::for_each( mMy.begin(), mMy.end(),
>> std::bind2nd(std::mem_fun_ref(&std::vector< myData >::resize), numMyData) );
>>
>>
>> in gcc4.2 it does not compile with error:
>>
>> no matching function for call to mem_fun_ref ..
>
> I am fairly sure the problem is that a single resize member function
> with this signature:
>
> void resize(size_type, const T& = T());
>
> was replaced with a pair of overloaded functions with these signatures:
>
> void resize(size_type);
> void resize(size_type, const T&);
>
> This change is allowed by the standard, but means that
> &vector<myData>::resize is no longer unambiguous.
>
>> i am pretty sure that i do not know how to implement ::resize correctly,
>> could someone tell me what i have to do get this fixed. i am happy if you
>> could show me a correct code example, but hints (books) and keywords that
>> could help me figure this out would also be greatly appreciated ..
>
> You can disambiguate the expression by providing a target type to
> convert to, so the compiler knows which overload you mean:
>
> typedef void (*resize_type)(std::vector< myData >::size_type);
>
> std::bind2nd(std::mem_fun_ref((resize_type)&std::vector< myData
>>::resize), numMyData) );


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]