|
Boost Users : |
Subject: Re: [Boost-users] metafunction question
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-05-11 19:04:06
>
> the return type cannot be parametrized based on the const-ness of
> "this". but parametrizing _functions_ based on constness rarely makes
> sense anyway, the best aproach imho is to keep the overloads but let
> them only handle the const/non-const specific stuff and forward the
> rest.
> in your example:
>
> private:
> node_ptr find_node(x) const;
> public:
> iterator find(x){ return iterator(find_node(x)); }
> const_iterator find(x) const{ return const_iterator(find_node(x)); }
>
>
That was exactly what I showed him. And that would work for "contained" stuff that was not contained by value. But, the find_node works using the inherited iterators, not his own mechanisms. So, the private iterator do_find(x) const finds itself limited to const_iterator in its own implementation from the getgo.
I was thinking
template <typename Collection, typename Iter= get_proper_iter<Collection>::type >
Iter do_find(Collection& c, find_params x);
and the question is, is there already a handy metafunction get_proper_iter<C> that will return C::const_iterator if C is const qualified, and C::iterator otherwise?
I suppose something like
mpl::if_<std::tr1::is_const<C>, typename C::const_iterator, typename C::iterator>
wrapped up as the interesting part of the metafunction. I've never tried anything like that, but I just read the first part of "C++ Template Metaprogramming" book and I see if_ used on page 63.
--John
TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
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