address-of a template class template member function

B

Brian Riis

Given:

template <typename T1, typename T2>
class A
{
public:
template <int I>
void B();
};

T1 and T2 are known, and I know which version of B I need. Say, e.g.

A<std::string, int>::B<1>()

I need to pass this function to a function.

My thought was that

f(&A<std::string, int>::B<1>);

should be possible, but g++ complains that the function argument is an
"<unknown type>".

So, is it possible to get the address of that function? If so, how? Or
is g++ misguided here?

Any help appreciated.
 
V

Victor Bazarov

Brian said:
Given:

template <typename T1, typename T2>
class A
{
public:
template <int I>
void B();
};

T1 and T2 are known, and I know which version of B I need. Say, e.g.

A<std::string, int>::B<1>()

I need to pass this function to a function.

My thought was that

f(&A<std::string, int>::B<1>);

should be possible, but g++ complains that the function argument is an
"<unknown type>".

So, is it possible to get the address of that function? If so, how? Or
is g++ misguided here?

What's the 'f's declaration? Is it declared to take a pointer to function
or a pointer to a member function of 'A'?

V
 
G

Gianni Mariani

Brian said:
Given:

template <typename T1, typename T2>
class A
{
public:
template <int I>
void B();
};

T1 and T2 are known, and I know which version of B I need. Say, e.g.

A<std::string, int>::B<1>()

I need to pass this function to a function.

My thought was that

f(&A<std::string, int>::B<1>);

should be possible, but g++ complains that the function argument is an
"<unknown type>".

So, is it possible to get the address of that function? If so, how? Or
is g++ misguided here?

Any help appreciated.

gcc 3.4.2 and 3.2.2 compiles this below just fine.

#include <string>

template <typename T1, typename T2>
class A
{
public:
template <int I>
void B();
};

// T1 and T2 are known, and I know which version of B I need. Say, e.g.

// A<std::string, int>::B<1>();

// I need to pass this function to a function.

// My thought was that

void (A<std::string, int>::*X)() = &A<std::string, int>::B<1>;

void f( void (A<std::string, int>::*)() );

int main()
{
f( &A<std::string, int>::B<1> );
}

Post some more code that describes your issue.
 
B

Brian Riis

Gianni said:
gcc 3.4.2 and 3.2.2 compiles this below just fine.

#include <string>

template <typename T1, typename T2> class A { public: template <int
I> void B(); };

// T1 and T2 are known, and I know which version of B I need. Say,
e.g.

// A<std::string, int>::B<1>();

// I need to pass this function to a function.

// My thought was that

void (A<std::string, int>::*X)() = &A<std::string, int>::B<1>;

void f( void (A<std::string, int>::*)() );

int main() { f( &A<std::string, int>::B<1> ); }

Post some more code that describes your issue.

Duh.. I was trying to simplify, and oversimplified... silly me. OK,
here's a more detailed go. Btw this should possibly be posted on the
boost ML instead, since it's two of their libraries I'm using, but g++'s
error message makes me think it's my address-of invocation that's
faulty. Anyway...

Boost Lambda Library and Boost.Tuple

I have a standard container of tuples, and need to find one with a
specific value in a known position. I though of using std::find_if and BLL.

typedef ::boost::tuples::tuple<std::string, int, int> myTuple;
using namespace boost::lambda;
int id = ...; // The key value in this case. The first int of myTuple.
std::vector<myTuple> m_vec; // A collection of tuples
std::vector<myTuple>::iterator i =
std::find_if(m_vec.begin(), m_vec.end(),
:):boost::lambda::bind(&myTuple::get<1>, _1) == id));

The "&myTuple::get<1>" part is what g++ is referring to as an "<unknown
type>". What i'm hoping to achieve is to get "i->get<1>()" compared to
"id", by binding the address of that function to the iterator.

And yes, I *do* know that I can easily achieve my goal by iterating the
vector myself, but I thought I might as well see if I can learn something.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top