
On 2014-09-01 21:27, Lorenzo Caminiti wrote:
On Mon, Sep 1, 2014 at 3:42 PM, Sebastian Redl
wrote: Either way, my need for static if is to conditionally have specific declarations in a class template or not, so unless the library can do this (the suggested usage won’t work in a pure declaration context), it’s no use to me.
I know... too bad enable_if cannot be used to disable these data member declarations.
The closest I ever came to this is to keep the data member declarations but make them "unusable". Not quite the same, but then you can use static if to program statements only when the data members are actually usable so they compile. For example:
#include "static_if.hpp" #include
#include #include <functional> class unusable : boost::noncopyable {};
template< bool B > struct x { typedef typename boost::mpl::if_c::type value_type; value_type v; // unfortunately, this can't actually be disable... so make it useless. <snip>
If we wanted to support this use case with a simpler syntax than inheritance then I think the smallest language change would be to permit data members of type void. Any use of such members would be ill-formed, and they would not be counted amongst the data members for the purposes of e.g. is_empty, is_standard_layout, etc. Then you could write the above code, with 'unusable' replaced by 'void'. If this misuse of void is too abhorrent, then a new keyword would of course be an option. Just a thought... someone keen could try to push this on std-proposals :). John Bytheway