Topic: overloading on function template parameters that


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 09 May 2014 15:41:09 +0200
Raw View
Hi,

this is not a proposal yet, but I have preferred to post it here as it
is related to a proposal I'm working on.

I would like to overload a make_error function

template <class ER, class E>
ER make_error(E e);

Note that ER doesn't appear as function parameter.

that can be used as

auto err = make_error<std::exception_ptr>(std::string("hhhh"));

The following doesn't works as there are ambiguity between the generic
overload (1) and the specific one (2).

namespace std {
template <class ER, class E>
ER make_error(E e) // (1)
{
   return ER(e);
}
template <class ER, class E
    , typename
std::enable_if<std::is_same<ER,std::exception_ptr>::value, int>::type = 0
 >
std::exception_ptr make_error(E e) // (2)
{
   return std::make_exception_ptr(e);
}

}
namespace boost {
template <class ER, class E, typename
std::enable_if<std::is_same<ER,none_t>::value, int>::type = 0
 >
none_t make_error(E)
{
   return none;
}
}

I have reached to make it work adding an indirection as follows

namespace std {
template <class ER, class E>
ER make_error(E e, ER*)
{
   return ER(e);
}

template <class ER, class E>
ER make_error(E e)
{
   ER* ptr=0;
   return make_error(e, ptr);
}

template <class E>
std::exception_ptr make_error(E e, std::exception_ptr*)
{
   return std::make_exception_ptr(e);
}
}
namespace boost {
template <class E>
none_t make_error(E, none_t*)
{
   return none;
}
}


Is this the correct way to define this generic interface?
Do you see any failures I have not identified in the design?
Do you know of a better way to manage with this kind of factory functions?

Vicente

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 9 May 2014 17:02:09 +0300
Raw View
On 9 May 2014 16:41, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
> Is this the correct way to define this generic interface?
> Do you see any failures I have not identified in the design?
> Do you know of a better way to manage with this kind of factory functions?


I'm pretty sure Concepts Lite will allow overloading on constraints,
so that will likely
provide a much superior alternative.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 09 May 2014 17:10:13 +0200
Raw View
Le 09/05/14 16:02, Ville Voutilainen a =C3=A9crit :
> On 9 May 2014 16:41, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> =
wrote:
>> Is this the correct way to define this generic interface?
>> Do you see any failures I have not identified in the design?
>> Do you know of a better way to manage with this kind of factory function=
s?
>
> I'm pretty sure Concepts Lite will allow overloading on constraints,
> so that will likely
> provide a much superior alternative.
>
Andrew could you confirm Ville comment?

Vicente

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 9 May 2014 20:08:56 +0300
Raw View
On 9 May 2014 18:10, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
>> I'm pretty sure Concepts Lite will allow overloading on constraints,
>> so that will likely
>> provide a much superior alternative.
>>
> Andrew could you confirm Ville comment?


For what it's worth, see
http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3929.pdf
[intro.intro]/4, second bullet:
"support function overloading and class template specialization based
on constraints".

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Nicola Gigante <nicola.gigante@gmail.com>
Date: Sat, 10 May 2014 09:46:27 +0200
Raw View
Il giorno 09/mag/2014, alle ore 15:41, "Vicente J. Botet Escriba" <vicente.=
botet@wanadoo.fr> ha scritto:
>=20
> Hi,
>=20
> this is not a proposal yet, but I have preferred to post it here as it is=
 related to a proposal I'm working on.
>=20
> I would like to overload a make_error function
>=20
> template <class ER, class E>
> ER make_error(E e);
>=20
> Note that ER doesn't appear as function parameter.
>=20
> that can be used as
>=20
> auto err =3D make_error<std::exception_ptr>(std::string("hhhh"));
>=20
> The following doesn't works as there are ambiguity between the generic ov=
erload (1) and the specific one (2).
>=20
> namespace std {
> template <class ER, class E>
> ER make_error(E e) // (1)
> {
>  return ER(e);
> }
> template <class ER, class E
>   , typename std::enable_if<std::is_same<ER,std::exception_ptr>::value, i=
nt>::type =3D 0
> >
> std::exception_ptr make_error(E e) // (2)
> {
>  return std::make_exception_ptr(e);
> }
>=20
> }
> namespace boost {
> template <class ER, class E, typename std::enable_if<std::is_same<ER,none=
_t>::value, int>::type =3D 0
> >
> none_t make_error(E)
> {
>  return none;
> }
> }
>=20
> I have reached to make it work adding an indirection as follows
>=20
> namespace std {
> template <class ER, class E>
> ER make_error(E e, ER*)
> {
>  return ER(e);
> }
>=20
> template <class ER, class E>
> ER make_error(E e)
> {
>  ER* ptr=3D0;
>  return make_error(e, ptr);
> }
>=20
> template <class E>
> std::exception_ptr make_error(E e, std::exception_ptr*)
> {
>  return std::make_exception_ptr(e);
> }
> }
> namespace boost {
> template <class E>
> none_t make_error(E, none_t*)
> {
>  return none;
> }
> }
>=20
>=20
> Is this the correct way to define this generic interface?
> Do you see any failures I have not identified in the design?
> Do you know of a better way to manage with this kind of factory functions=
?
>=20

I don't think you need new language features here. I'd delegate the creatio=
n of the error object to a function in a trait class with different special=
izations so you have a single factory function. In this way you also obtain=
 the flexibility for the user to customize the behavior for their error typ=
es in the same way you do for exception_ptr.

> Vicente

Bye,
Nicola

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 10 May 2014 16:07:32 +0800
Raw View
--Apple-Mail=_F54A9CD0-A87B-40BD-BA80-F2974602C7BB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-05-09, at 9:41 PM, Vicente J. Botet Escriba <vicente.botet@wanadoo.=
fr> wrote:

> Is this the correct way to define this generic interface?

I don't think it's generic at all. exception_ptr is a different animal from=
 exception, so make_error should not be able to produce both.

> Do you see any failures I have not identified in the design?
> Do you know of a better way to manage with this kind of factory functions=
?

You seem to have reinvented tag dispatching. In general, a function templat=
e with "partial specializations" will need some form of dispatching, either=
 by tags or SFINAE, and either at the interface overload set or behind a di=
spatcher wrapper function as you did.

None of this seems like a big deal to me. On one hand, you hit a case where=
 you want function template partial specialization. On the other hand, in t=
his case it's a code smell that the interface is overextended.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_F54A9CD0-A87B-40BD-BA80-F2974602C7BB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;05&ndash;09, at 9:41 PM, Vicente J. Botet Escriba &lt;<a href=3D"mail=
to:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>&gt; wrote:</div><=
br class=3D"Apple-interchange-newline"><blockquote type=3D"cite">Is this th=
e correct way to define this generic interface?<br></blockquote><div><br></=
div><div>I don&rsquo;t think it&rsquo;s generic at all.&nbsp;<font face=3D"=
Courier">exception_ptr</font> is a different animal from&nbsp;<font face=3D=
"Courier">exception</font>, so <font face=3D"Courier">make_error</font> sho=
uld not be able to produce both.</div><br><blockquote type=3D"cite">Do you =
see any failures I have not identified in the design?<br>Do you know of a b=
etter way to manage with this kind of factory functions?<br></blockquote><d=
iv><br></div><div>You seem to have reinvented tag dispatching. In general, =
a function template with &ldquo;partial specializations&rdquo; will need so=
me form of dispatching, either by tags or SFINAE, and either at the interfa=
ce overload set or behind a dispatcher wrapper function as you did.</div></=
div><br><div>None of this seems like a big deal to me. On one hand, you hit=
 a case where you want function template partial specialization. On the oth=
er hand, in this case it&rsquo;s a code smell that the interface is overext=
ended.</div><div><br></div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_F54A9CD0-A87B-40BD-BA80-F2974602C7BB--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 10 May 2014 13:02:07 +0200
Raw View
Le 10/05/14 09:46, Nicola Gigante a =E9crit :
> Il giorno 09/mag/2014, alle ore 15:41, "Vicente J. Botet Escriba" <vicent=
e.botet@wanadoo.fr> ha scritto:
>> Hi,
>>
>> this is not a proposal yet, but I have preferred to post it here as it i=
s related to a proposal I'm working on.
>>
>> I would like to overload a make_error function
>>
>> template <class ER, class E>
>> ER make_error(E e);
>>
>> Note that ER doesn't appear as function parameter.
>>
>> that can be used as
>>
>> auto err =3D make_error<std::exception_ptr>(std::string("hhhh"));
>>
>> The following doesn't works as there are ambiguity between the generic o=
verload (1) and the specific one (2).
>>
>> namespace std {
>> template <class ER, class E>
>> ER make_error(E e) // (1)
>> {
>>   return ER(e);
>> }
>> template <class ER, class E
>>    , typename std::enable_if<std::is_same<ER,std::exception_ptr>::value,=
 int>::type =3D 0
>> std::exception_ptr make_error(E e) // (2)
>> {
>>   return std::make_exception_ptr(e);
>> }
>>
>> }
>> namespace boost {
>> template <class ER, class E, typename std::enable_if<std::is_same<ER,non=
e_t>::value, int>::type =3D 0
>> none_t make_error(E)
>> {
>>   return none;
>> }
>> }
>>
>> I have reached to make it work adding an indirection as follows
>>
>> namespace std {
>> template <class ER, class E>
>> ER make_error(E e, ER*)
>> {
>>   return ER(e);
>> }
>>
>> template <class ER, class E>
>> ER make_error(E e)
>> {
>>   ER* ptr=3D0;
>>   return make_error(e, ptr);
>> }
>>
>> template <class E>
>> std::exception_ptr make_error(E e, std::exception_ptr*)
>> {
>>   return std::make_exception_ptr(e);
>> }
>> }
>> namespace boost {
>> template <class E>
>> none_t make_error(E, none_t*)
>> {
>>   return none;
>> }
>> }
>>
>>
>> Is this the correct way to define this generic interface?
>> Do you see any failures I have not identified in the design?
>> Do you know of a better way to manage with this kind of factory function=
s?
>>
> I don't think you need new language features here. I'd delegate the creat=
ion of the error object to a function in a trait class with different speci=
alizations so you have a single factory function. In this way you also obta=
in the flexibility for the user to customize the behavior for their error t=
ypes in the same way you do for exception_ptr.
>
I'm not requesting a new language feature.

My intention is of course  that this function could be "specialized" by=20
the user (See the "specialization" for moons::none_t. I've considered=20
the trait already and currently expected<E,T> uses it already. In fact=20
the design of the post is just an alternative based more on a Concept=20
than on a Trait.

Vicente


--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 10 May 2014 13:02:11 +0200
Raw View
This is a multi-part message in MIME format.
--------------000505000603040300020603
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 10/05/14 10:07, David Krauss a =E9crit :
>
> On 2014--05--09, at 9:41 PM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
>> Is this the correct way to define this generic interface?
>
> I don't think it's generic at all. exception_ptr is a different animal=20
> from exception, so make_error should not be able to produce both.
>
The expected<E,T> class I'm working could be instantiated with

expected<std::exception_ptr,T>
expected<std::string,T> // here string could be seen as a error


Currently I have used an internal trait that allows to convert from the=20
error it self to the storage "from_error()" and that know how to thow an=20
exception when needed "bad_access()". Instead of making this traits=20
public so that other kind of errors can be managed (e.g. an error that=20
ensures that has been read or otherwise terminate the program, or be=20
able to associate the exception that is thrown, error_condition could be=20
thrown using system_error exception), I was wondering if I couldn't=20
define an Error concept. The operation of this concept would be

template <class E> ER make_error(E);
void retrow(ER);

Is this over-designed?

The cases that I would take care of are
* be able to store an error that ensures that the error has been read=20
before destruction or otherwise terminate the program,
* be able to associate the exception that is thrown, error_condition=20
could be thrown using system_error exception instead of the=20
bad_expected_access throw currently.


>> Do you see any failures I have not identified in the design?
>> Do you know of a better way to manage with this kind of factory=20
>> functions?
>
> You seem to have reinvented tag dispatching. In general, a function=20
> template with "partial specializations" will need some form of=20
> dispatching, either by tags or SFINAE, and either at the interface=20
> overload set or behind a dispatcher wrapper function as you did.
yes, the tag I have used is just the pointer type :)
>
> None of this seems like a big deal to me. On one hand, you hit a case=20
> where you want function template partial specialization. On the other=20
> hand, in this case it's a code smell that the interface is overextended.
>
>
Maybe you are right and I'm looking for a bad concept :(

Vicente

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--------------000505000603040300020603
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Le 10/05/14 10:07, David Krauss a
      &eacute;crit&nbsp;:<br>
    </div>
    <blockquote
      cite="mid:67EC0741-C576-4E2B-AA57-04D7280DEEB5@gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <br>
      <div>
        <div>On 2014&#8211;05&#8211;09, at 9:41 PM, Vicente J. Botet Escriba &lt;<a
            moz-do-not-send="true"
            href="mailto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>&gt;
          wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">Is this the correct way to define this
          generic interface?<br>
        </blockquote>
        <div><br>
        </div>
        <div>I don&#8217;t think it&#8217;s generic at all.&nbsp;<font face="Courier">exception_ptr</font>
          is a different animal from&nbsp;<font face="Courier">exception</font>,
          so <font face="Courier">make_error</font> should not be able
          to produce both.</div>
        <br>
      </div>
    </blockquote>
    The expected&lt;E,T&gt; class I'm working could be instantiated
    with&nbsp; <br>
    <br>
    expected&lt;std::exception_ptr,T&gt;<br>
    expected&lt;std::string,T&gt; // here string could be seen as a
    error<br>
    <br>
    <br>
    Currently I have used an internal trait that allows to convert from
    the error it self to the storage "from_error()" and that know how to
    thow an exception when needed "bad_access()". Instead of making this
    traits public so that other kind of errors can be managed (e.g. an
    error that ensures that has been read or otherwise terminate the
    program, or be able to associate the exception that is thrown,
    error_condition could be thrown using system_error exception), I was
    wondering if I couldn't define an Error concept. The operation of
    this concept would be <br>
    <br>
    template &lt;class E&gt; ER make_error(E); <br>
    void retrow(ER);<br>
    <br>
    Is this over-designed?<br>
    <br>
    The cases that I would take care of are <br>
    * be able to store an error that ensures that the error has been
    read before destruction or otherwise terminate the program, <br>
    * be able to associate the exception that is thrown, error_condition
    could be thrown using system_error exception instead of the
    bad_expected_access throw currently.<br>
    <br>
    <br>
    <blockquote
      cite="mid:67EC0741-C576-4E2B-AA57-04D7280DEEB5@gmail.com"
      type="cite">
      <div>
        <blockquote type="cite">Do you see any failures I have not
          identified in the design?<br>
          Do you know of a better way to manage with this kind of
          factory functions?<br>
        </blockquote>
        <div><br>
        </div>
        <div>You seem to have reinvented tag dispatching. In general, a
          function template with &#8220;partial specializations&#8221; will need
          some form of dispatching, either by tags or SFINAE, and either
          at the interface overload set or behind a dispatcher wrapper
          function as you did.</div>
      </div>
    </blockquote>
    yes, the tag I have used is just the pointer type :)<br>
    <blockquote
      cite="mid:67EC0741-C576-4E2B-AA57-04D7280DEEB5@gmail.com"
      type="cite"><br>
      <div>None of this seems like a big deal to me. On one hand, you
        hit a case where you want function template partial
        specialization. On the other hand, in this case it&#8217;s a code
        smell that the interface is overextended.</div>
      <div><br>
      </div>
      <br>
    </blockquote>
    Maybe you are right and I'm looking for a bad concept :(<br>
    <br>
    Vicente<br>
  </body>
</html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

--------------000505000603040300020603--

.


Author: Jan Herrmann <jherrmann79@gmx.de>
Date: Mon, 12 May 2014 11:06:34 +0200
Raw View
On 09.05.2014 15:41, Vicente J. Botet Escriba wrote:
> Hi,
>
> this is not a proposal yet, but I have preferred to post it here as it
> is related to a proposal I'm working on.
>
> I would like to overload a make_error function
>
> template <class ER, class E>
> ER make_error(E e);
>
> Note that ER doesn't appear as function parameter.
>
> that can be used as
>
> auto err = make_error<std::exception_ptr>(std::string("hhhh"));
>
> The following doesn't works as there are ambiguity between the generic
> overload (1) and the specific one (2).
>
> namespace std {
> template <class ER, class E>
> ER make_error(E e) // (1)
> {
>    return ER(e);
> }
> template <class ER, class E
>     , typename
> std::enable_if<std::is_same<ER,std::exception_ptr>::value, int>::type = 0
>  >
> std::exception_ptr make_error(E e) // (2)
> {
>    return std::make_exception_ptr(e);
> }
>
> }
> namespace boost {
> template <class ER, class E, typename
> std::enable_if<std::is_same<ER,none_t>::value, int>::type = 0
>  >
> none_t make_error(E)
> {
>    return none;
> }
> }
>
> I have reached to make it work adding an indirection as follows
>
> namespace std {
> template <class ER, class E>
> ER make_error(E e, ER*)
> {
>    return ER(e);
> }
>
> template <class ER, class E>
> ER make_error(E e)
> {
>    ER* ptr=0;
>    return make_error(e, ptr);
> }
>
> template <class E>
> std::exception_ptr make_error(E e, std::exception_ptr*)
> {
>    return std::make_exception_ptr(e);
> }
> }
> namespace boost {
> template <class E>
> none_t make_error(E, none_t*)
> {
>    return none;
> }
> }
>
>
> Is this the correct way to define this generic interface?
> Do you see any failures I have not identified in the design?
> Do you know of a better way to manage with this kind of factory functions?

I have implemented this similarly with help of a parameter of type
std::common_type<T> (or better with a template alias like ret_type):

template<class R, class E>
R make_error(std::common_type<R>, E e)


The problem with both designs is the effect of ADL with both approaches.
In your design with the namespaces of ER and E, in my design with std
and the namespace of E.

I have a working example at
http://coliru.stacked-crooked.com/a/c97773a5d073afdc

>
> Vicente
>


Jan Herrmann

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 17 May 2014 07:56:08 -0700 (PDT)
Raw View
------=_Part_27_23971891.1400338568683
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



Le vendredi 9 mai 2014 19:08:56 UTC+2, Ville Voutilainen a =C3=A9crit :
>
> On 9 May 2014 18:10, Vicente J. Botet Escriba <vicent...@wanadoo.fr<javas=
cript:>>=20
> wrote:=20
> >> I'm pretty sure Concepts Lite will allow overloading on constraints,=
=20
> >> so that will likely=20
> >> provide a much superior alternative.=20
> >>=20
> > Andrew could you confirm Ville comment?=20
>
>
> For what it's worth, see=20
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3929.pdf=20
> [intro.intro]/4, second bullet:=20
> "support function overloading and class template specialization based=20
> on constraints".=20
>

Thanks Ville for the pointer,

However, I'm not sure a call to a function with a template parameter is=20
subject to overloading, e.g.  make_error<E1>

  E1 e1 =3D make_error<E1>(e);

and that only make_error it is.

What am I missing something?

Vicente

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_27_23971891.1400338568683
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>Le vendredi 9 mai 2014 19:08:56 UTC+2, Ville Vouti=
lainen a =C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin=
: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 9=
 May 2014 18:10, Vicente J. Botet Escriba &lt;<a href=3D"javascript:" targe=
t=3D"_blank" gdf-obfuscated-mailto=3D"_Rixz1y7dKUJ" onmousedown=3D"this.hre=
f=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';return=
 true;">vicent...@wanadoo.fr</a>&gt; wrote:
<br>&gt;&gt; I'm pretty sure Concepts Lite will allow overloading on constr=
aints,
<br>&gt;&gt; so that will likely
<br>&gt;&gt; provide a much superior alternative.
<br>&gt;&gt;
<br>&gt; Andrew could you confirm Ville comment?
<br>
<br>
<br>For what it's worth, see
<br><a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3929.pd=
f" target=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url?=
q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2014%2=
Fn3929.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNE8fW_i_FXKXRewcpK9nfyfxedm6w'=
;return true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3=
A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2014%2Fn3929.pdf=
\46sa\75D\46sntz\0751\46usg\75AFQjCNE8fW_i_FXKXRewcpK9nfyfxedm6w';return tr=
ue;">http://open-std.org/JTC1/SC22/<wbr>WG21/docs/papers/2014/n3929.<wbr>pd=
f</a>
<br>[intro.intro]/4, second bullet:
<br>"support function overloading and class template specialization based
<br>on constraints".
<br></blockquote><div><br></div><div>Thanks Ville for the pointer,</div><di=
v><br></div><div>However, I'm not sure a call to a function with a template=
 parameter is subject to overloading, e.g. &nbsp;make_error&lt;E1&gt;</div>=
<div><br></div><div>&nbsp; E1 e1 =3D make_error&lt;E1&gt;(e);</div><div><br=
></div><div>and that only make_error it is.</div><div><br></div><div>What a=
m I missing something?</div><div><br></div><div>Vicente</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_27_23971891.1400338568683--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 17 May 2014 08:02:20 -0700 (PDT)
Raw View
------=_Part_51_32532044.1400338940505
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



Le lundi 12 mai 2014 11:06:34 UTC+2, Jan Herrmann a =C3=A9crit :
>
> On 09.05.2014 15:41, Vicente J. Botet Escriba wrote:=20
> > Hi,=20
> >=20
> > this is not a proposal yet, but I have preferred to post it here as it=
=20
> > is related to a proposal I'm working on.=20
> >=20
> > I would like to overload a make_error function=20
> >=20
> > template <class ER, class E>=20
> > ER make_error(E e);=20
> >=20
> > Note that ER doesn't appear as function parameter.=20
> >=20
> > that can be used as=20
> >=20
> > auto err =3D make_error<std::exception_ptr>(std::string("hhhh"));=20
> <snip>=20
> > Is this the correct way to define this generic interface?=20
> > Do you see any failures I have not identified in the design?=20
> > Do you know of a better way to manage with this kind of factory=20
> functions?=20
>
> I have implemented this similarly with help of a parameter of type=20
> std::common_type<T> (or better with a template alias like ret_type):=20
>
> template<class R, class E>=20
> R make_error(std::common_type<R>, E e)=20
>
>
> The problem with both designs is the effect of ADL with both approaches.=
=20
> In your design with the namespaces of ER and E, in my design with std=20
> and the namespace of E.=20
>
> Hi,

could you show a case in which this ADL introduction would be an issue?
Vicente

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_51_32532044.1400338940505
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>Le lundi 12 mai 2014 11:06:34 UTC+2, Jan Herrmann =
a =C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 09.05.20=
14 15:41, Vicente J. Botet Escriba wrote:
<br>&gt; Hi,
<br>&gt;
<br>&gt; this is not a proposal yet, but I have preferred to post it here a=
s it
<br>&gt; is related to a proposal I'm working on.
<br>&gt;
<br>&gt; I would like to overload a make_error function
<br>&gt;
<br>&gt; template &lt;class ER, class E&gt;
<br>&gt; ER make_error(E e);
<br>&gt;
<br>&gt; Note that ER doesn't appear as function parameter.
<br>&gt;
<br>&gt; that can be used as
<br>&gt;
<br>&gt; auto err =3D make_error&lt;std::exception_ptr&gt;<wbr>(std::string=
("hhhh"));
<br>&lt;snip&gt;
<br>&gt; Is this the correct way to define this generic interface?
<br>&gt; Do you see any failures I have not identified in the design?
<br>&gt; Do you know of a better way to manage with this kind of factory fu=
nctions?
<br>
<br>I have implemented this similarly with help of a parameter of type=20
<br>std::common_type&lt;T&gt; (or better with a template alias like ret_typ=
e):
<br>
<br>template&lt;class R, class E&gt;
<br>R make_error(std::common_type&lt;R&gt;<wbr>, E e)
<br>
<br>
<br>The problem with both designs is the effect of ADL with both approaches=
..=20
<br>In your design with the namespaces of ER and E, in my design with std=
=20
<br>and the namespace of E.
<br>
<br></blockquote><div>Hi,</div><div><br></div><div>could you show a case in=
 which this ADL introduction would be an issue?</div><div>Vicente</div></di=
v>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_51_32532044.1400338940505--

.


Author: tomaszkam@gmail.com
Date: Wed, 9 Jul 2014 14:00:18 -0700 (PDT)
Raw View
------=_Part_175_15803343.1404939618858
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu pi=C4=85tek, 9 maja 2014 15:41:09 UTC+2 u=C5=BCytkownik Vicente J. B=
otet=20
Escriba napisa=C5=82:
>
> Hi,=20
>
> this is not a proposal yet, but I have preferred to post it here as it=20
> is related to a proposal I'm working on.=20
>
> I would like to overload a make_error function=20
>
> template <class ER, class E>=20
> ER make_error(E e);=20
>
> Note that ER doesn't appear as function parameter.=20
>
> that can be used as=20
>
> auto err =3D make_error<std::exception_ptr>(std::string("hhhh"));=20
>
> The following doesn't works as there are ambiguity between the generic=20
> overload (1) and the specific one (2).=20
>
> namespace std {=20
> template <class ER, class E>=20
> ER make_error(E e) // (1)=20
> {=20
>    return ER(e);=20
> }=20
> template <class ER, class E=20
>     , typename=20
> std::enable_if<std::is_same<ER,std::exception_ptr>::value, int>::type =3D=
 0=20
>  >=20
> std::exception_ptr make_error(E e) // (2)=20
> {=20
>    return std::make_exception_ptr(e);=20
> }=20
>
> }=20
> namespace boost {=20
> template <class ER, class E, typename=20
> std::enable_if<std::is_same<ER,none_t>::value, int>::type =3D 0=20
>  >=20
> none_t make_error(E)=20
> {=20
>    return none;=20
> }=20
> }=20
>
> I have reached to make it work adding an indirection as follows=20
>
> namespace std {=20
> template <class ER, class E>=20
> ER make_error(E e, ER*)=20
> {=20
>    return ER(e);=20
> }=20
>
> template <class ER, class E>=20
> ER make_error(E e)=20
> {=20
>    ER* ptr=3D0;=20
>    return make_error(e, ptr);=20
> }=20
>
> template <class E>=20
> std::exception_ptr make_error(E e, std::exception_ptr*)=20
> {=20
>    return std::make_exception_ptr(e);=20
> }=20
> }=20
> namespace boost {=20
> template <class E>=20
> none_t make_error(E, none_t*)=20
> {=20
>    return none;=20
> }=20
> }=20
>
>
> Is this the correct way to define this generic interface?=20
> Do you see any failures I have not identified in the design?=20
> Do you know of a better way to manage with this kind of factory functions=
?=20
>
> Vicente=20
>

The solution is simple, use a class if you need a specialized version of=20
algorithm for specialized type:
namespace impl
{
   template<typename ER> //gernic one
   struct make_error
   {
     template<typename E>
     ER operator()(E e) const
     {
       return ER(e);
     }
   };

   template<> //specialized
   struct make_error<std::exception_ptr>
   {
     template<typename E>
     std::exception_ptr operator()(E e) const
     {
       return std::make_exception_ptr(e); ;
     }
   }
}

And then use you template factory in a template function:
template <class ER, class E>=20
ER make_error(E e) // (1)=20
{=20
   return impl::make_error<ER>{}(e);
}=20

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_175_15803343.1404939618858
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu pi=C4=85tek, 9 maja 2014 15:41:09 UTC+2 u=
=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;">Hi,
<br>
<br>this is not a proposal yet, but I have preferred to post it here as it=
=20
<br>is related to a proposal I'm working on.
<br>
<br>I would like to overload a make_error function
<br>
<br>template &lt;class ER, class E&gt;
<br>ER make_error(E e);
<br>
<br>Note that ER doesn't appear as function parameter.
<br>
<br>that can be used as
<br>
<br>auto err =3D make_error&lt;std::exception_ptr&gt;<wbr>(std::string("hhh=
h"));
<br>
<br>The following doesn't works as there are ambiguity between the generic=
=20
<br>overload (1) and the specific one (2).
<br>
<br>namespace std {
<br>template &lt;class ER, class E&gt;
<br>ER make_error(E e) // (1)
<br>{
<br>&nbsp; &nbsp;return ER(e);
<br>}
<br>template &lt;class ER, class E
<br>&nbsp; &nbsp; , typename=20
<br>std::enable_if&lt;std::is_same&lt;<wbr>ER,std::exception_ptr&gt;::value=
, int&gt;::type =3D 0
<br>&nbsp;&gt;
<br>std::exception_ptr make_error(E e) // (2)
<br>{
<br>&nbsp; &nbsp;return std::make_exception_ptr(e);
<br>}
<br>
<br>}
<br>namespace boost {
<br>template &lt;class ER, class E, typename=20
<br>std::enable_if&lt;std::is_same&lt;<wbr>ER,none_t&gt;::value, int&gt;::t=
ype =3D 0
<br>&nbsp;&gt;
<br>none_t make_error(E)
<br>{
<br>&nbsp; &nbsp;return none;
<br>}
<br>}
<br>
<br>I have reached to make it work adding an indirection as follows
<br>
<br>namespace std {
<br>template &lt;class ER, class E&gt;
<br>ER make_error(E e, ER*)
<br>{
<br>&nbsp; &nbsp;return ER(e);
<br>}
<br>
<br>template &lt;class ER, class E&gt;
<br>ER make_error(E e)
<br>{
<br>&nbsp; &nbsp;ER* ptr=3D0;
<br>&nbsp; &nbsp;return make_error(e, ptr);
<br>}
<br>
<br>template &lt;class E&gt;
<br>std::exception_ptr make_error(E e, std::exception_ptr*)
<br>{
<br>&nbsp; &nbsp;return std::make_exception_ptr(e);
<br>}
<br>}
<br>namespace boost {
<br>template &lt;class E&gt;
<br>none_t make_error(E, none_t*)
<br>{
<br>&nbsp; &nbsp;return none;
<br>}
<br>}
<br>
<br>
<br>Is this the correct way to define this generic interface?
<br>Do you see any failures I have not identified in the design?
<br>Do you know of a better way to manage with this kind of factory functio=
ns?
<br>
<br>Vicente
<br></blockquote><div><br>The solution is simple, use a class if you need a=
 specialized version of algorithm for specialized type:<br>namespace impl<b=
r>{<br>&nbsp;&nbsp; template&lt;typename ER&gt; //gernic one<br>&nbsp;&nbsp=
; struct make_error<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; template&=
lt;typename E&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; ER operator()(E e) const<br>&=
nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ER=
(e);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; };<br><br>&nbsp;&nbsp; t=
emplate&lt;&gt; //specialized<br>&nbsp;&nbsp; struct make_error&lt;std::exc=
eption_ptr&gt;<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; template&lt;ty=
pename E&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; std::exception_ptr operator()(E e)=
 const<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; return std::make_exception_ptr(e);
;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; }<br>}<br><br>And then use =
you template factory in a template function:<br>template &lt;class ER, clas=
s E&gt;
<br>ER make_error(E e) // (1)
<br>{
<br>&nbsp; &nbsp;return impl::make_error&lt;ER&gt;{}(e);<br>}
<br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_175_15803343.1404939618858--

.