|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2003-12-03 14:00:31
From: Douglas Paul Gregor <gregod_at_[hidden]>
>
> struct some_safe_bool_nested_class {
> int my_data_member;
> };
>
> typedef int some_safe_bool_nested_class::*safe_bool_type;
>
> You don't ever need an instance of some_safe_bool_nested_class.
Here's the context for what you're proposing. It's code that
Dave posted in an earlier message.
template <class T>
struct bool_testable
{
private:
struct impl { int x; };
typedef int impl::*safe_bool;
public:
operator safe_bool() const
{
return !*static_cast<T const*>(this) ? 0 : &impl::x;
}
};
I'm clearly missing something. How can there be an address for
impl::x if there's no instance of impl?
Were impl::x declared static, there could be an instance --
though you'd need to define it somewhere -- so you could take its
address. Lacking that, "impl::x" must refer to something and so
it must either come from a dummy dm in bool_testable or from the
derived class (through a template parameter).
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk