Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My previous answer didn't provide sufficient detail, and the solution is really not so simple. This is a complete snippet showing how to do it:</p> <pre><code>#include &lt;boost/flyweight/factory_tag.hpp&gt; #include &lt;boost/flyweight/hashed_factory_fwd.hpp&gt; #include &lt;boost/multi_index_container.hpp&gt; #include &lt;boost/multi_index/identity.hpp&gt; #include &lt;boost/multi_index/hashed_index.hpp&gt; #include &lt;boost/mpl/aux_/lambda_support.hpp&gt; #include &lt;boost/mpl/if.hpp&gt; class bucket_query { public: typedef std::size_t size_type; virtual size_type bucket_count()const=0; virtual size_type max_bucket_count()const=0; virtual size_type bucket_size(size_type n)const=0; }; static bucket_query* bucket_query_ptr=0; template&lt; typename Entry,typename Key, typename Hash=boost::mpl::na,typename Pred=boost::mpl::na, typename Allocator=boost::mpl::na &gt; class accessible_hashed_factory_class: public boost::flyweights::factory_marker, public bucket_query { struct index_list: boost::mpl::vector1&lt; boost::multi_index::hashed_unique&lt; boost::multi_index::identity&lt;Entry&gt;, typename boost::mpl::if_&lt; boost::mpl::is_na&lt;Hash&gt;, boost::hash&lt;Key&gt;, Hash &gt;::type, typename boost::mpl::if_&lt; boost::mpl::is_na&lt;Pred&gt;, std::equal_to&lt;Key&gt;, Pred &gt;::type &gt; &gt; {}; typedef boost::multi_index::multi_index_container&lt; Entry, index_list, typename boost::mpl::if_&lt; boost::mpl::is_na&lt;Allocator&gt;, std::allocator&lt;Entry&gt;, Allocator &gt;::type &gt; container_type; public: typedef const Entry* handle_type; accessible_hashed_factory_class(){bucket_query_ptr=this;} handle_type insert(const Entry&amp; x) { return &amp;*cont.insert(x).first; } void erase(handle_type h) { cont.erase(cont.iterator_to(*h)); } static const Entry&amp; entry(handle_type h){return *h;} typedef std::size_t size_type; virtual size_type bucket_count()const{return cont.bucket_count();} virtual size_type max_bucket_count()const{return cont.max_bucket_count();} virtual size_type bucket_size(size_type n)const{return cont.bucket_size(n);} private: container_type cont; public: typedef accessible_hashed_factory_class type; BOOST_MPL_AUX_LAMBDA_SUPPORT( 5,accessible_hashed_factory_class,(Entry,Key,Hash,Pred,Allocator)) }; template&lt; typename Hash=boost::mpl::na,typename Pred=boost::mpl::na, typename Allocator=boost::mpl::na BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION &gt; struct accessible_hashed_factory:boost::flyweights::factory_marker { template&lt;typename Entry,typename Key&gt; struct apply: boost::mpl::apply2&lt; accessible_hashed_factory_class&lt; boost::mpl::_1,boost::mpl::_2,Hash,Pred,Allocator &gt;, Entry,Key &gt; {}; }; /* testing */ #include &lt;boost/flyweight.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; int main() { typedef boost::flyweight&lt;std::string,accessible_hashed_factory&lt;&gt; &gt; string_fw; string_fw s1("hello"),s2("hello"),s3("bye"); std::cout&lt;&lt;"number of buckets: "&lt;&lt;bucket_query_ptr-&gt;bucket_count()&lt;&lt;std::endl; } </code></pre> <p>The idea is: <code>accessible_hashed_factory_class</code> autoregisters itself via <code>bucket_query_ptr</code> exposing an interface for consulting bucket count etc. (<code>bucket_query</code>) that you can adapt and extend according to your needs. The solution is far from elegant but might solve your problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload