|
Boost Users : |
Subject: Re: [Boost-users] [MultiIndex] Visual C++ 10 issue
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-05-11 09:23:34
On Tue, 11 May 2010, joaquin_at_[hidden] wrote:
> Jeremiah Willcock escribió:
>> On Mon, 10 May 2010, Richard Webb wrote:
>>
>>
>>> Sounds like the same problem as
>>> https://svn.boost.org/trac/boost/ticket/3594
>>>
>>
>> It seems like it is. Is the workaround that complicated, though? Is there
>> a way to get some of that factored out to reuse in other Boost libraries?
>> Would putting an explicit cast to ... std::pair::* in the template argument
>> work instead?
>>
>
> Hi Jeremiah,
>
> The problem is not a bug with VC++ 10, but a collateral effect of the
> way std::pair is implemented in the stdlib provided for this compiler
> --namely, by deriving from an implementation-specific _Pair_base class
> where the members are actually defined. This reduced test case can help
> explain the problem:
Could this be viewed as a library issue, then, or is the type of
&std::pair<a, b>::first not considered to be part of the library's
interface? It does seem bad that any use of pointers-to-members is
fragile to the use of mixins or hidden base classes as part of a class's
implementation.
(snip)
> The workaround applied at https://svn.boost.org/trac/boost/ticket/3594
> works, but it's probably overkill (and uses the objectionable
> member_offset, which is really meant to be used as a last resort for
> legacy compilers). A nicer workaround consists in providing a
> user-defined key extractor:
>
> template<typename First,typename Second>
> class pair_first_extractor
> {
> typedef std::pair<First,Second> value_type;
>
> public:
> typedef First result_type;
>
> const result_type& operator()(const value_type& x)const
> {
> return x.first;
> }
>
> result_type& operator()(value_type& x)const
> {
> return x.first;
> }
> };
>
> typedef multi_index::multi_index_container<
> std::pair<key_type, value_type>,
> multi_index::indexed_by<
> multi_index::sequenced<>,
> multi_index::hashed_unique<
> pair_first_extractor<key_type, value_type>
> >
> >
> > ghost_cells_type;
OK. Should that code (for std::pairs) be part of multi_index anywhere?
It would seem like other users would use parts of pairs as keys.
Otherwise, can I copy your code into BGL (under the Boost license)? Also,
would just a simple cast on the pointer-to-member type work, or are those
not allowed in non-type template arguments?
-- Jeremiah Willcock
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net