Hicham,

please see my comments below:

On Wed, Mar 4, 2009 at 1:54 PM, Hicham Mouline <hicham@mouline.org> 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.


 


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.
 


regards,

Regards,
Ovanes