|
Boost : |
From: Daniel James (daniel_at_[hidden])
Date: 2004-07-27 19:44:39
On Wed, 28 Jul 2004 09:24:07 +1000, Thorsten Ottosen wrote:
> "Eric Niebler" <eric_at_[hidden]> wrote in message
> news:4106A244.2020800_at_boost-consulting.com...
> |
> | Thorsten Ottosen wrote:
> | >
> | > I've put meself in a funny situation. I have a class with an begin()
> | > end() members, but I wan't to call boost::begin() boost::end()
> | > without the boost:: prefix so ADL is functional. Can that be done?
> | >
> | At the point of use, bring boost::begin and boost::end into local scope
> | with using declarations. That should hide the versions in class scope.
>
> ok, and how do you do that in an initializer list? :-)
You put it into a separate function?
template <class T>
typename boost::iterator_of<T>::type your_begin(T const& x)
{
using boost::begin;
return begin(x);
}
template <class T>
your_class<T>::your_class(T const& x) : begin_(your_begin(x)) {}
boost::iterator_of might not be right for you, but I'm guessing that since
you're going to store the result somewhere, you should be able to come up
with a reasonable alternative.
If you really must do it in the initialiser list, another alternative is
to put the class' implementation into a separate namespace.
namespace obscure
{
using boost::begin;
template <class T>
class your_class
{
iterator begin_;
public:
your_class(T const& x) : begin_(begin(x)) {}
iterator your_begin();
};
}
template <class T>
class your_class
{
obscure::your_class<T> impl_;
public:
your_class(T const& x) : impl_(x) {}
iterator begin() { return impl_.your_begin(); }
}
So, what's the flaw in the plan?
Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk