Boost logo

Boost :

Subject: Re: [boost] [static_if] Is there interest in a `static if` emulation library?
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2014-09-01 21:24:19


pfultz2 wrote
> Another way accomplishing this is to pass in an identity function:
> ...
> Then you can call it like this:
>
> template< typename T >
> void assign ( T& x, T const& y )
> {
> x = y;
>
> static_if&lt;boost::has_equal_to&lt;T&gt;::value>([](auto f)
> {
> assert(f(x) == f(y));
> std::cout << "asserted for: " << typeid(T).name() <<
> std::endl;
> })
> .else_([] (auto)
> {
> std::cout << "cannot assert for: " << typeid(T).name() <<
> std::endl;
> });
> }
>
> The identity function will make non-dependent types dependent, so this
> will
> compile.

Clever! However, IMO the `auto f` would look somewhat arbitrary to users
(I'd have to explain it "magically" comes from within the implementation so
you don't have to the bind...). So I'd probably stick with the bind because
even if more verbose it's workings are more obvious to the users. Thank you
for the suggestion.

--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/static-if-Is-there-interest-in-a-static-if-emulation-library-tp4667118p4667158.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk