220 10602 <536E072F.4060101@wanadoo.fr> article
Path: news.gmane.org!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: overloading on function template parameters that
 don't appear as function parameters
Date: Sat, 10 May 2014 13:02:07 +0200
Lines: 110
Approved: news@gmane.org
Message-ID: <536E072F.4060101@wanadoo.fr>
References: <536CDAF5.4020407@wanadoo.fr> <5978C7F2-F9AF-4B48-B4DF-B3273299F550@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1399719740 13159 80.91.229.3 (10 May 2014 11:02:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 10 May 2014 11:02:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDH67CONY4PBBMEOXCNQKGQEVN4WIII@isocpp.org Sat May 10 13:02:13 2014
Return-path: <std-proposals+bncBDH67CONY4PBBMEOXCNQKGQEVN4WIII@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f197.google.com ([209.85.217.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDH67CONY4PBBMEOXCNQKGQEVN4WIII@isocpp.org>)
	id 1Wj52g-0000o3-9R
	for gclcip-std-proposals@m.gmane.org; Sat, 10 May 2014 13:02:10 +0200
Original-Received: by mail-lb0-f197.google.com with SMTP id w7sf2976292lbi.8
        for <gclcip-std-proposals@m.gmane.org>; Sat, 10 May 2014 04:02:09 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type:content-transfer-encoding;
        bh=sK/hH7ARmnZwokTJpRjzV1GESpR7LGuKkQqZvtgEHa8=;
        b=EuU2mrrdjzCGw6X1Yr4aNg8I4MObSyt7Qu4yd2l/ZHNG2kEIYKhZPXCzZS13SICQQh
         eMtpLkIlyXRtbk4T+eLA7YhJq5rKIMB0bixoV8swhzJmr2FkumzpvGOigu9PXveovvGY
         EezhENvoRjuS86A64O8hT0p5qhYaWdh/RgqLozPsK2zB54qGGojIYbAmrO0wswqL0MW9
         kS6VVMK558a9LoqetVio/9kxTUsKuw0jF/Jw/+1Hso5QdIOdQ1w8PjTiKGpvOCGxBRBt
         3VO+pLov4IKRJWJOw2YWkBja7RdddNq+LKV34gWohZq8crLSIWUpZsh4QV53wRUQOHJG
         uVE 
X-Gm-Message-State: ALoCoQlyBQI0ouwt7fnvZrHAVcH1ukhWh+xfgl2JGxMvD2LEdFxIJXFLlaNQAEx1c2eSQJYhr3lz
X-Received: by 10.180.93.74 with SMTP id cs10mr878362wib.6.1399719729759;
        Sat, 10 May 2014 04:02:09 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.90.241 with SMTP id bz17ls255139wib.33.gmail; Sat, 10 May
 2014 04:02:08 -0700 (PDT)
X-Received: by 10.180.212.107 with SMTP id nj11mr7447866wic.40.1399719728637;
        Sat, 10 May 2014 04:02:08 -0700 (PDT)
Original-Received: from smtp.smtpout.orange.fr (smtp04.smtpout.orange.fr. [80.12.242.126])
        by mx.google.com with ESMTP id ku2si2545809wjb.102.2014.05.10.04.02.08
        for <std-proposals@isocpp.org>;
        Sat, 10 May 2014 04:02:08 -0700 (PDT)
Received-SPF: none (google.com: vicente.botet@wanadoo.fr does not designate permitted sender hosts) client-ip=80.12.242.126;
Original-Received: from new-host.home ([2.11.192.45])
	by mwinf5d59 with ME
	id 0B271o00e0zDXEA03B27sK; Sat, 10 May 2014 13:02:08 +0200
X-ME-Helo: new-host.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Sat, 10 May 2014 13:02:08 +0200
X-ME-IP: 2.11.192.45
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To: <5978C7F2-F9AF-4B48-B4DF-B3273299F550@gmail.com>
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: vicente.botet@wanadoo.fr does not designate permitted sender
 hosts) smtp.mail=vicente.botet@wanadoo.fr
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:10602
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10602>

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/.

.
