Boost logo

Boost :

Subject: Re: [boost] [static_if] Is there interest in a `static if` emulation library?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-09-18 02:07:17


Le 18/09/14 00:28, lcaminiti a écrit :
> Sebastian Redl wrote
>> On 08 Sep 2014, at 6:50, Lorenzo Caminiti <
>> lorcaminiti@
>> > wrote:
>>> ...
>>> 1. Why is not possible to use enabled_if with template variables?
>>> ...
>> enable_if only works in conjunction with SFINAE.
>>
>> Look at that line of code of yours. First, think about what this line is:
>>
>> n<1>;
>>
>> It’s not an explicit template instantiation, even though it may look like
>> that. It’s an expression statement, containing a single declaration
>> reference expression, referencing the variable template instantiation
>> n<1>.
>> ...
>> I hope issue #2 has already been sufficiently answered by the others.
> I understand. Thanks to you and everyone else for the explanations. It seems
> the best (and possibly only) way to disable data member declarations based
> on compile-time constants is via inheritance after all.
>
> Given that:
> 1. Disabling data members with a static-if library seems not possible;
> 2. And, based on all critiques in N3613, we will likely never have language
> support for static-if.
>
> I will reiterate my original question:
> Is there interest in a Boost.StaticIf library to do something like the
> following?
>
> template< typename Iter, typename Dist >
> void myadvance ( Iter& i, Dist n ) {
> Iter* p = &i;
> static_if<is_random_access_iterator&lt;Iter>::value>(
> std::bind([ ] ( auto p, auto n ) {
> *p += n;
> }, p, n)
> ).template elif<is_bidirectional_iterator&lt;Iter>::value>(
> std::bind([ ] ( auto p, auto n ) {
> if(n >= 0) while(n--) ++*p;
> else while(n++) --*p;
> }, p, n)
> ).template elif<is_input_iterator&lt;Iter>::value>(
> std::bind([ ] ( auto p, auto n ) {
> while(n--) ++*p;
> }, p, n)
> ).else_(
> std::bind([ ] ( auto false_ ) {
> static_assert(false_, "requires InputIterator<Iter>");
> }, std::false_type())
> );
> }

Yes, I think this is an interesting addition to Boost.

Lorenzo, as the scope of your static_if emulation is restricted to void
expressions would you mind to rename it, e.g. call_if?

Thanks for you work,
Vicente


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