Boost logo

Boost :

Subject: Re: [boost] [bind/lambda] Matching signature constness?
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2008-12-10 13:42:23


Robert Jones wrote:
> Here's a bit of code (and my apologies for it's length, but I'm unsure
> which bit is the failure point)
>

[snip]

> template < bool >
> struct cmp_detail
> {
> template < typename T >
> static bool cmp( const T & lhs, const T & rhs )
> {
> return lhs != rhs;
> }
> };
>
> template < >
> struct cmp_detail< true >
> {
> template < typename T, std :: size_t sz >
> static bool cmp( const T ( & lhs )[ sz ], const T ( & rhs )[ sz ] )
> {
> using boost :: lambda :: _1;
> using boost :: lambda :: bind;
> using boost :: lambda :: var;
>
> boost :: function< bool( unsigned ) > cmp_element =
> bind( cmp_detail< boost :: is_array< T > :: value > :: cmp,
> var( lhs )[ _1 ], var( rhs )[ _1 ] );
>

[snip]

>
> The problem is the bind call in cmp_detail<true>::cmp(...). Error is this
>
> block.cpp: In static member function `static bool <unnamed>::cmp_detail<
> true>::cmp(const T (&)[sz], const T (&)[sz]) [w
> ith T = int[16], unsigned int sz = 16u]':
> block.cpp:45: instantiated from `bool <unnamed>::cmp(const T&, const T&)
> [with T = int[16][16]]'
> block.cpp:61: instantiated from here
> block.cpp:32: error: no matching function for call to `bind(<unknown type>,

[snip]

I see two problems here:
1. cmp_detail<true>::cmp is a template, but you don't specify its
template parameters in the bind expression.
2. You missed the & operator while taking address of the member function
cmp.

So I guess it should be:

  bind( &cmp_detail< boost :: is_array< T > :: value > :: cmp< T >,
        var( lhs )[ _1 ], var( rhs )[ _1 ] );


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk