[cfe-dev] [libc++] c++14 return type deduction usage should be limited

Zhihao Yuan lichray at gmail.com
Tue Aug 6 15:39:59 PDT 2013


Hi, hackers:

I noticed that in include/functional:

   _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const

is widely used to support C++14 type deduced function objects:

  http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2012/n3421.htm

However, in the standard text, the return type is specified with

  -> decltype(std::forward<T>(t) + std::forward<U>(u));

There is a slight difference between using return type deduction and
writing `decltype` out explicitly, because the later case triggers
SFINAE, while the first case does not.  See:

  http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3638.html

   "SFINAE

    Since the return type is deduced by instantiating the template, if the
    instantiation is ill-formed, this causes an error rather than a
    substitution failure. [...]"

I suggest to obey the standard here, even such a behavior may
(arguably) not be intentional.

BTW, in the adopted text, each of the new type deduced function
class has a `is_transparent` typedef, so...

-- 
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: function_objs_1y.2.patch
Type: application/octet-stream
Size: 6879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130806/5b3c6b49/attachment.obj>


More information about the cfe-dev mailing list