Boost logo

Boost Users :

Subject: Re: [Boost-users] Tag dispatching
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-03-04 08:29:54


> ----- Original Message -----
> From: "Ovanes Markarian" <om_boost_at_[hidden]>
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Tag dispatching
> Date: Wed, 4 Mar 2009 14:12:09 +0100
>
> Hicham,
>
> please see my comments below:
>
> On Wed, Mar 4, 2009 at 1:54 PM, Hicham Mouline <hicham_at_[hidden]> wrote:
>
> > Hello,
> >
> > I have a question about tag dispatching (for e.g. the std::advance()
> > function in the std lib, as described for instance in
> > http://www.boost.org/community/generic_programming.html#tag_dispatching)
> >
> > 1. The call to
> > detail::advance_dispatch(i, n, category);
> > I don't understand. category is a type not an object, it should be
> > category(), right?
>
>
> typename *iterator_traits<InputIterator>::iterator_category* category;
> detail::advance_dispatch(i, n, *category*);
>
> here is no typedef used, so category is an instance of iterator_category. In
> the template context you have to prefix it with typename keyword. Using:
>
> typename *iterator_traits<InputIterator>::iterator_category* category();
>
> declares a function, which returns iterator_category, but does not create a
> class instance.
ah yes of course. I misread the typename as typedef, thanks.
category is an auto instance.
Can it be also written also as a temporary
etail::advance_dispatch(i, n, iterator_traits<InputIterator>::iterator_category() );

> > 2. If I am correct,
> > the tags are empty structs which I assume allows modern compilers
> > (g++4, msvc8/9, intel) to optimize away the creation of that category
> > object ?
>
> This is compiler dependent. ISO C++ 03 standard requires an instance of an
> empty type to be at least 1 byte big. To check if that happens read the
> documentation to the corresponding compiler.

> > 3. If i am still correct, I have a tag which has no members except 1 static
> > function that returns void.
> > Would that optimization still apply?
>
> Applies the same as in 2.
Whether the compiler prints sizeof(myType) as 1byte or something else has no bearing
on whether it doesn't create an instance at runtime, right?
need to read their docs (though it's quite hard to see where for g++ for e.g.)

thanks very much,

regards,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net