Boost logo

Boost :

From: Daniel Earwicker (daniel.earwicker_at_[hidden])
Date: 2005-11-02 16:16:58


David Abrahams:
> On conforming compilers, the library uses overloading to look up the
> value associated with any given keyword. I assumed that having two of
> the same keyword would cause an ambiguity error at lookup time:

7.3.3/12 of the standard appears to deal with this: "When a
using-declaration brings names from a base class into a derived class
scope, member functions in the derived class override and/or hide
member functions with the same name and parameter types in a
base-class (rather than conflicting)."

i.e. a working model of the same keyword twice on an arg_list:

   struct keyword {};

   struct base
   {
       int operator[](const keyword &) { return 1; }
   };

   struct derived : public base
   {
       using base::operator[];

       int operator[](const keyword &) { return 2; }
   };

   int main()
   {
       return derived()[keyword()];
   }

> The problem with this (aside from the use of an ALL_CAPS name for
> something other than a macro)

Thanks for the tip!

> is that it costs O(N^2) instantiations,
> where N is the number of arguments. OTOH you could do it with
> overloading (or just use an mpl::set, which uses overloading
> internally) to do it in O(N).

Oooh, that's much better. With used_keywords as an empty set in
empty_arg_list, all it needs in arg_list is:

   BOOST_STATIC_ASSERT((!boost::mpl::has_key<
           typename Next::used_keywords, key_type>::type::value));

   typedef typename mpl::insert<typename Next::used_keywords,
           key_type>::type used_keywords;

Or is there already something that captures the above pattern, i.e.
refuses to insert a duplicate?

--Daniel.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk