Boost logo

Boost :

Subject: [boost] [mpl] Error in map docs (or bug)
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2008-10-26 19:43:30


I think I've found an error in the MPL docs (In trunk and 1.35, and
presumably everything in between).

The documentation for mpl::map state that "count<m,k>::type" yields "The
number of elements with the key k in m", where in fact what it returns
is the number of elements *equal* to k in m. This is consistent with
the documentation of mpl::count. I suspect this is an error in the docs
rather than a bug, since there is also mpl::has_key, which serves the
purpose count claims to be serving (but isn't).

Consider this code:

#include <boost/mpl/has_key.hpp>
#include <boost/mpl/count.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/insert.hpp>

using namespace boost::mpl;

typedef set<
    int
>::type my_set;

typedef map<
    boost::mpl::pair<int, int>
>::type my_map;

BOOST_MPL_ASSERT((has_key<my_set, int >::type));
BOOST_MPL_ASSERT((count<my_set, int >::type));
BOOST_MPL_ASSERT((has_key<my_map, int >::type));
BOOST_MPL_ASSERT((count<my_map, int >::type));
BOOST_MPL_ASSERT((count<my_map, pair<int,int> >::type));

The fourth assertion fails. If the map docs were accurate then it would
be the fifth assertion that failed.

The same error is in the Associative Sequence docs, and perhaps other
places.

John Bytheway


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