[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

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

Hermann

10/10/2008 11:41:00 PM

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??
4 Answers

Barry

10/11/2008 1:18:00 AM

0

On Oct 11, 7:41 am, Hermann <Hermann.Rich...@gmail.com> wrote:
> 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.ht...
para.3

Hermann

10/11/2008 2:06:00 AM

0

On Oct 10, 9:17 pm, Barry <dhb2...@gmail.com> wrote:
>
> 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??

Barry

10/11/2008 12:03:00 PM

0

On Oct 11, 10:06 am, Hermann <Hermann.Rich...@gmail.com> wrote:
> On Oct 10, 9:17 pm, Barry <dhb2...@gmail.com> wrote:
>
>
>
> > 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??

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".

--
Best Regards
Barry

Hendrik Schober

10/14/2008 7:19:00 AM

0

Hermann wrote:
> 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