[Boost-bugs] [Boost C++ Libraries] #9953: lazy_enable_if is not sfinae friendly

Subject: [Boost-bugs] [Boost C++ Libraries] #9953: lazy_enable_if is not sfinae friendly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-04-25 10:53:02


#9953: lazy_enable_if is not sfinae friendly
------------------------------+---------------------------
 Reporter: hui.li@… | Owner: no-maintainer
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: utility
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------
 The following code fails to compile, even though boost::result_of itself
 is sfinae friendly.
 {{{
 template < typename T >
 typename boost::lazy_enable_if_c<
   boost::is_class<T>::value,
   boost::result_of<T(int)>
>::type
 test(int){}

 template < typename >
 void test(...) {}

 struct A{}; // boost::result_of<A(int)> is a valid type that doesn't have
 a member called "type"

 int main(int argc, const char * argv[])
 {
   test<A>(0); // test<A>(int) meant to be a substitution failure
   return 0;
 }
 }}}
 I'm not sure if this is a bug/flaw, or a lack of feature, or maybe this
 kind of use is deliberately disallowed for some reason, but it could be
 very useful if {{{lazy_enable_if_c<bool B, typename T>}}} etc support uses
 when {{{typename T::type}}} itself may cause a substitution failure.

 Proposing to change implementation of {{{lazy_enable_if_c}}} and
 {{{lazy_disable_if_c}}} to:
 {{{
 template <bool B, class T>
 struct lazy_enable_if_c : T {}; // inherits from T

 template <class T>
 struct lazy_enable_if_c<false, T> {};

 template <bool B, class T = void>
 struct disable_if_c : T {}; // inherits from T

 template <class T>
 struct disable_if_c<true, T> {};
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9953>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC