Boost logo

Boost Users :

Subject: Re: [Boost-users] [Enable-if] Selectively instantiating methods.
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2011-09-23 04:12:55


2011/9/23 Robert Jones <robertgbjones_at_[hidden]>

> Hi All
>
> This doesn't work.
>
> template<typename T> struct S
> {
> typename disable_if<is_const<T>, int>::type mutating_method();
> };
>
> I understand why not, although only after the compiler threw it out, but
> obviously (in hindsight),
> the method itself is not a template, so can't be selectively instantiated.
>
> The question is whether and how I can achieve the effect I'm after, ie.,
> that the method
> is not present if the struct is instantiated with a const type?
>

You'll need to specialize S or do something to the similar effect (e.g.,
have two base classes and inherit from one of them depending on the template
argument).

Roman Perepelitsa.



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