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-17 18:28:36

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

template< typename Iter, typename Dist >
void myadvance ( Iter& i, Dist n ) {
    Iter* p = &i;
        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)
        std::bind([ ] ( auto false_ ) {
            static_assert(false_, "requires InputIterator<Iter>");
        }, std::false_type())

Thanks again.

View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at