Question about bind

I am learning how to use std::tr1::bind, but there are some questions
I don't know how to solve

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void adaptSpanRegionMono(int const MAX_AL, float const CONFIDENT_LV, int const OFFSET)
{}

template<typename T>
void testArg(T haha)
{
  int const MAX_AL = 10;
  float const CONFIDENT_LV = 10;
  int const OFFSET = 10;
  haha(MAX_AL, CONFIDENT_LV, OFFSET); //ok
  haha(OFFSET, CONFIDENT_LV, MAX_AL); //ok
  haha(2, CONFIDENT_LV, MAX_AL) ; //fault
}

void testBind()
{
  using namespace std::tr1::placeholders;
  testArg(std::tr1::bind(adaptSpanRegionMono, _1, _2, _3) );
}


error message

error: no match for call to '(std::tr1::_Bind<void (*(std::tr1::_Placeholder<1>, std::tr1::_Placeholder<2>, std::tr1::_Placeholder<3>))(int, float, int)>) (int, const float&, const int&)


Thanks a lot
Hm, that's odd...I'm not really sure why that it happening.

I just tried it using boost::bind() and it worked fine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void adaptSpanRegionMono(int const MAX_AL, float const CONFIDENT_LV, int const OFFSET)
{}

template<typename T>
void testArg(T haha)
{
  int const MAX_AL = 10;
  float const CONFIDENT_LV = 10;
  int const OFFSET = 10;
  haha(MAX_AL, CONFIDENT_LV, OFFSET); //ok
  haha(OFFSET, CONFIDENT_LV, MAX_AL); //ok
  haha(2, CONFIDENT_LV, MAX_AL) ; //this works too
}

int main() {
    testArg(boost::bind(adaptSpanRegionMono, _1, _2, _3));
}
Thanks, after I change it to boost::bind, the problem is solved
This is because the c++0x features of my gcc still have some bugs or my mistakes?

my os : windows xp sp3(32)
compilers : tdm gcc-4.5.1
It's not your mistake.
Sorry, I have another problem again
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
template<typename accStrategy = float>
int const adaptSR(int const MAX_AL, float const CONFIDENT_LV, int const OFFSET, accStrategy PLAN)
{
  return 1; 
}

template<typename accStrategy = float>
int const adaptSR(int const MAX_AL, float const CONFIDENT_LV, int const OFFSET)
{
  return 1;  
}

template<typename T>
void testArg(T haha)
{
  int const MAX_AL = 10;
  float const CONFIDENT_LV = 10;
  int const OFFSET = 10;
  haha(MAX_AL, CONFIDENT_LV, OFFSET);
}

void testBind()
{
  //boost::accumulators::accMeanStDv<float> accMSD;
  bindClass bc;
  float a = 3;
  testArg(boost::bind<int>(adaptSR<int>, _1, _2, _3) );
  testArg(boost::bind<int>(adaptSR<float>, _1, _2, _3, a) );
  testArg(boost::bind<int>(adaptSR<bindClass>, _1, _2, _3, bc ));
  testArg(boost::bind<int>(adaptSR<bindClass>, _1, _2, _3, boost::cref(bc) ));
}


error message

error: too few arguments to function


I don't know how to solve the overloaded problem like this one
Thanks a lot
Last edited on
Mmmm, that's a little nastier. Just looking at what you've written above, does the second adaptSR have to be templated? It does not use its template parameter in the parameter list. If the template can be removed, then I think you have an easy fix.
It does not use its template parameter in the parameter list

The template parameter has been used or not is not a big deal for this case
I am trying different conditions on boost::bind and want to find out what kind of situations
it could be used and what kind of situations it could not be used
I try to look at the website of boost::bind, but it never mention how to solve this kind of problem(or I overlooked?)

If the template can be removed, then I think you have an easy fix.

I remove the template and recompile it, it really have an easy fix
But what if I need template(I want to pass a strategy to the function)?
could boost::function give me an easy fix?
Thanks

ps:for now the most easiest way is change the name of the function
Last edited on
Topic archived. No new replies allowed.