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<Iter>::value>( std::bind([ ] ( auto p, auto n ) { *p += n; }, p, n) ).template elif<is_bidirectional_iterator<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<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()) ); } Thanks again. --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/static-if-Is-there-interest-in-a-static-i... Sent from the Boost - Dev mailing list archive at Nabble.com.