
Le 18/09/14 00:28, lcaminiti a écrit :
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
Sebastian Redl wrote 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
::value>( std::bind([ ] ( auto p, auto n ) { *p += n; }, p, n) ).template elif ::value>( std::bind([ ] ( auto p, auto n ) { if(n >= 0) while(n--) ++*p; else while(n++) --*p; }, p, n) ).template elif ::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