|
Boost : |
Subject: Re: [boost] [static_if] Is there interest in a `static if` emulation library?
From: Sohail Somani (sohail_at_[hidden])
Date: 2014-09-18 15:42:19
On 2014-09-01, 11:00 AM, Robert Ramey wrote:
> OK I see this now. I've used my method on a regular basis with good
> results - but it seems that I never had a case where the compile
> would fail on the false branch so it never came up for me.
Actually, I've used your method (not sure if it *is* yours, but I saw it
in serialization code) for cases where it wouldn't compile on the false
branch. In the linked example, there are 4 cases, but same idea as I
think where you used it in serialization.
The idea is something like this:
template<typename T>
void do_whatever_impl(boost::mpl::true_) {
T::whatever();
}
template<typename T>
void do_whatever_impl(boost::mpl::false_) {
// no T::whatever()
whatever();
}
template<typename T>
void do_whatever() {
do_whatever_impl(has_whatever<T>());
}
PS: I know I have to change to make_shared, just too lazy right now.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk