Boost logo

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>());
}

https://bitbucket.org/cheez/dicpp/src/b78d05e976922f36959616cd2d98e55e5b1113d3/include/di/registry.hpp?at=default#cl-78

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