stl_vector.h ::resize in llvm gcc4.2

Jonathan Wakely jwakely.gcc@gmail.com
Wed Feb 29 17:58:00 GMT 2012


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) );



More information about the Libstdc++ mailing list