How to now the type of a boost::list_of object??

H

Hermann

I remember there was a trick to get the type of a anonymous variable
(like a boost::lambda functor or a boost::list_of object) so you can
store it in a variable.
You had to generate a specific compilation error and then look for the
type definition in the error text that the compiler outputs (or
somethig like that).

Does anyone know exactly how to do it??
 
B

Barry

I remember there was a trick to get the type of a anonymous variable
(like a boost::lambda functor or a boost::list_of object) so you can
store it in a variable.
You had to generate a specific compilation error and then look for the
type definition in the error text that the compiler outputs (or
somethig like that).

Does anyone know exactly how to do it??

Wild guess: "How to now" is "How to name"

boost::list_of returns something that is implementation-defined.
all we have to know is that what types it it convertible to.
this idiom is like boost::bind, which returns something convertible
to boost::function. when we need to store what boost::bind returns,
use boost::function.

the types that supports boost::list_of
http://www.boost.org/doc/libs/1_36_0/libs/assign/doc/index.html#list_of
para.3
 
H

Hermann

Wild guess: "How to now" is "How to name"

No, I just missed a kay (How to Know...).

boost::list_of returns something that is implementation-defined.

I didn't know boost::list_of were part of a standard. I mean, Boost
library is just that, right? a library. Or is it an implementation of
a standard??
 
B

Barry

No, I just missed a kay (How to Know...).


I didn't know boost::list_of were part of a standard. I mean, Boost
library is just that, right? a library. Or is it an implementation of
a standard??

Yes, you were right.

I change "implementation details" into "implementation-defined",
just as the document writes.
What I wanted to say is that the library implementer does NOT
expect the user to "know" the exact type of what boost::list_of
returns.

In this issue, it's really painful when debugging this kind of
compile-time error, as typeid(...).name() prints not helpful
information if not useless. Other ways? I'm also expecting to "know".
 
H

Hendrik Schober

Hermann said:
I remember there was a trick to get the type of a anonymous variable
(like a boost::lambda functor or a boost::list_of object) so you can
store it in a variable.
You had to generate a specific compilation error and then look for the
type definition in the error text that the compiler outputs (or
somethig like that).

Does anyone know exactly how to do it??

Do you mean something like this

template< typename T >
i_have_no_idea<T>::some_type f(T);

template< typename T >
void g(T o)
{
what_is_the_type tmp = f(o);
}

where you don't know 'what_is_the_type'?
Doesn't your compiler name the type in its complaints
when you try to make 'tmp' a 'bool', 'int', 'std::string',
or 'foo'? I believe that, with my compiler, passing some
unknown type to something like this

template< typename T >
void dummy(T)
{
typedef typename T::some_thing_that_does_not_exist U;
}

(or an equivalent meta functions, if you're in compile-time
land) usually does the trick to get it to name 'T'.

Schobi
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top