2

考虑这段代码,它编译成功:

#include <boost/intrusive/unordered_set.hpp>

using namespace boost::intrusive;

typedef unordered_set_member_hook<> Hook;

struct Item
{
    Hook hook;
};

typedef unordered_set<Item,
    member_hook<Item, Hook, &Item::hook>,
    size_type<uint32_t> > Map;

static_assert(4 == sizeof(typename Map::size_type));
static_assert(8 == sizeof(decltype(Map::suggested_upper_bucket_count(1000))));

文档代码中,suggested_upper_bucket_count()都是这样声明的:

static size_type suggested_upper_bucket_count(size_type);

那怎么可能Map::size_type是 4 个字节 ( uint32_t) 而结果suggested_upper_bucket_count()却是 8 个字节呢?

现场观看:https ://godbolt.org/g/3Sz8Xj

4

1 回答 1

1

这是 Boost 1.65 中修复的错误

于 2017-09-08T12:53:48.587 回答