|
Boost Users : |
From: me22 (me22.ca_at_[hidden])
Date: 2007-06-06 14:23:50
On 06/06/07, Bill Buklis <boostuser_at_[hidden]> wrote:
> For a template class I'd like to add * and -> operators for types that
> support it (mainly pointers). However, most instantiations of this class
> won't be pointers and therefore these operators won't be valid. I understand
> that enable_if can't directly support member functions. But, how can I do
> the equivalent of this?
>
> [code snipped]
>
SFINAE -- you don't even need boost:
template <typename T>
struct holder {
T value;
T operator->() const { return value; }
};
struct foo { int bar; };
int main() {
holder<foo*> a; // compiles
a->bar = 0; // compiles
holder<int> b; // compiles
// b->bar = 0; // wouldn't compile
}
~ Scott McMurray
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