220 32567 <1620864.HL4j5jKv18@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: relaxing rules for ternary operator. Allow
 incompatible types.
Date: Sun, 21 May 2017 17:12:16 -0700
Lines: 84
Approved: news@gmane.org
Message-ID: <1620864.HL4j5jKv18@tjmaciei-mobl1>
References: <1b5ee8eb-53df-4e98-af2f-829c7bc2e5b2@isocpp.org> <1678895.0nQhqNqFQE@tjmaciei-mobl1> <b75d4532-bb6e-4b66-8f9b-a2a94b679e96@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1495411940 17437 195.159.176.226 (22 May 2017 00:12:20 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 22 May 2017 00:12:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBYWZRDEQKGQEDFWJQ5Q@isocpp.org Mon May 22 02:12:15 2017
Return-path: <std-proposals+bncBCB4TK757YBRBYWZRDEQKGQEDFWJQ5Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f69.google.com ([209.85.215.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBYWZRDEQKGQEDFWJQ5Q@isocpp.org>)
	id 1dCaxK-0004PV-A4
	for gclcip-std-proposals@m.gmane.org; Mon, 22 May 2017 02:12:14 +0200
Original-Received: by mail-lf0-f69.google.com with SMTP id k75sf9925625lfg.12
        for <gclcip-std-proposals@m.gmane.org>; Sun, 21 May 2017 17:12:20 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1495411940; cv=pass;
        d=google.com; s=arc-20160816;
        b=HFhAmUPCexaIrMIhnFGtnyYNImtAa+ToyhhGwpoowqDuTyriVwl/xtGxRW98gtAB+f
         jvbgYnpKGNeQGRuNhg6BWN9DheeWGjd3g02zfQtuPX0CmYW82DWQ345uVvHmYxwOH1X4
         XEv6HfdO4PUDtzcWH5QMzJs++Z00sAV5Y7QP68DioX4uGJTvr1VkmK6jPJcviLh+NJgV
         hlSAUlYp1fh4ahkBCen6PasaTh/VkliDZfzCkUIxit2k21WP2uf9KB8ITjF9QfDlmkn5
         48krCGqAwlwZwB3GW4N/YXK4t/1P7MW0RtayFT0krT6y1OXm7oHFnIUGjtUw2EFBSKM6
         hpYA==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=UcDKfmWtNpIaqDuCqkZtXUNNQ505g/yjUoUPBRT+lm8=;
        b=PQpXTuQNHxX+Rgudnq/JRncvcnTc4un64EUnbCzCe60ToAjw5TaMNepYfkWa3ydR39
         nBdbkDFNX4ffz1SFJu/peQ3noZkjyqOkB0XtrnIl8VWkYg20frmxUV/HlH/D2GD8H89q
         pvezUQJiOBsAKn3mNF/jZz/Z515YkrlDIh726pdnUPk7gfTIgg2ORnAbxHQV+rhlgaQP
         XQrB2l8HkslR+Tay4PecAXgwQ3Us0cu7Llvp5ys0hT3V3f5wQosbN+HMir0FJOZMlJ4F
         Cf7JSBtsHxPLahhjyBym26S/GVPThncDEE6j3lWMXafA40707GO90I7erSmwYXGfnYrQ
         BNxQ==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=UcDKfmWtNpIaqDuCqkZtXUNNQ505g/yjUoUPBRT+lm8=;
        b=zrtRPUg1++/fwo6bhfFr+RqKevsOE8wR6LJc1+jAhTZyRHAjP/wHkbuaqs4DGOtRiz
         iyRNr5aTrGIBNftOMt/Zjm4f4I7R4h0Pwnqk6872JvsJpsGQOJMMq3h+GkVkQ3pCrjhq
         HmJBRnRS4hhoOGlPfHmrQpf+CSt322P3L22l1GMB9FqlyTcfBl+9nPv2eg2q7poVxo1C
         k25piCrrfgup3txAuVKLuPJ7NFmFK6fO8MHSsU3JNr3aFVjCz2tCWYX/mxBBjvoY0GSD
         Yv5GkbJQxN3UVWexCecbstB2YOIEm6R9fKfHnhDAF6nHPH5lVwgtBNkfPmNbw+QfcRe8
         KVGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=UcDKfmWtNpIaqDuCqkZtXUNNQ505g/yjUoUPBRT+lm8=;
        b=llnNVLpfLMrsdcKBJkHO2PAxCfHHhwqbS8h6LfW7OHsHnrbCjd+vAh7HRU1ZlNfPmc
         4n+b2Es1lPkssnOHalRNsCR052lqWlyqBqF8/poQBB6asSHpV0uvKfTzXEj6Tmx4Lo3f
         5bLWbw1A8Ms6roA6EK+TutvUMUknt0fEoiSmHluFTbJbza8aP2r+zE8/akFNycQMcuUb
         SlKxHUyPTwM/PQ+ylPIcdJ0HQ/2uGHXrzSDeWVsnNFIC77eKE+xyK2R3ExxDbfZf8Rt+
         r2dNVvcG/IjVsapMExFLBs+Z3ay+vXvjryx2ROWRzJ3Gvukpe4LDlwL20BDM7my3DgH2
         8hwg==
X-Gm-Message-State: AODbwcD/LMLWTCyOWA1qduDmik+sKbPyBu62E0Gwrf+jui1w60QqpWWj
	TRH5UxbAEgPpvlqy
X-Received: by 10.46.92.131 with SMTP id q125mr2195407ljb.0.1495411939912;
        Sun, 21 May 2017 17:12:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.15.76 with SMTP id 73ls76098wmp.20.gmail; Sun, 21 May 2017
 17:12:18 -0700 (PDT)
X-Received: by 10.223.161.144 with SMTP id u16mr9076329wru.145.1495411938548;
        Sun, 21 May 2017 17:12:18 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1495411938; cv=none;
        d=google.com; s=arc-20160816;
        b=bNx3Bj+S788dBb9gx2+415O3ftsB+ySEQ0TloKaI27X+uZsQnxhBOBR2THbd28Smgy
         qk7wK3TEmZ10QjqezRDs07jIBpbqK+4gSCcxiA4P35/g8O8OPSOtEj7WzCOl4xPyDyhV
         arRS6GqhWx7xDPIT3bgqqQ3+nCFRfYGLqzfwbm3XxqQcV2CqP+fWJ713Hdn97Llf/2uK
         3PERMYyQSzokx0vkmskg/3amimuFHA4NcYYKi4HGfnk5gv13SZYdzZvii1uOc6Qt7dzN
         YTqXytfCTGyvhPv42fYZXvoT7gBVo8PJ8lCEzSBzHRr6mwGqsbJtHlM4xepp82fBs5+I
         uVWg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=QlJ/kggkZiOJzO4JkbXyUMnHR3Kc0sOYCHTOL0/oN20=;
        b=dmpzx/jwv0u7zlfx+13Sl7+5XgNv2OcZ07SuDP2RT2bhApQsJ2rDFAo6Zhn4Yutw0E
         RxLuwuuYnIy2zUn6PAlFfgfLQQfl7Qf9FXb2Gg6KFKIDIg/O7CVawfp7Qv4IPND7zT9t
         dN2eFC3yuEegyrfR3P5SpcX1EfDvP5G3JF9TNP0AgnO0Ofd4pKVCcRdOUPGOttyHZjR/
         AhrjGIsdCyOymTJvWYR0EfyTAKBFwNn0ozTVgmbSGtO8jIcFYeRsuK3seAakiRO29uLS
         37P4FU0yAMO3WNvrN6ZZCk1v9MgmMhJoAJ9RFzsFWUDT7+3UOW9ORAgpsf48RGlt58YG
         5FCw==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id s7si10365952wrb.187.2017.05.21.17.12.18
        for <std-proposals@isocpp.org>;
        Sun, 21 May 2017 17:12:18 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl1.localnet (unknown [IPv6:2601:1c0:4501:5f9f:8466:3462:d05f:7085])
	by gondolin.macieira.info (Postfix) with ESMTPSA id C443D12C001
	for <std-proposals@isocpp.org>; Sun, 21 May 2017 17:12:17 -0700 (PDT)
In-Reply-To: <b75d4532-bb6e-4b66-8f9b-a2a94b679e96@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:32567
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32567>

On domingo, 21 de maio de 2017 13:54:51 PDT ma.kalbfuss@web.de wrote:
> Yeah, i realize that. This is something you have to consider if you're
> using templates extensively. 

No, it isn't. Today, the use of templates does not imply exponential growth of 
generated code.

That is something completely new with your proposal.

> This is not the right solution for everything.
> I think in most cases, you use one or at most two ternary operators in one
> place. For three or more ternary operators the runtime overhead is
> assumably the lesser of two evils. But even if it grows exponentially, the
> constants are pretty small. Normaly only a few instructions are involved.

Not necessarily. Remember that you may not reevaluate the condition, so either 
this generates completely separate code paths (and thus the exponential 
expansion) or the result of the evaluation is stored in a hidden variable that 
is evaluated every time you access that automatic variable. 

That is, when you write:

	auto x = runtime_condition1 ? A{} : B{}; 
	auto y = runtime_conditoin2 ? C{} : D{};
	x.f();

This expands to either:

	if (runtime_condition1) {
		auto x = A{};
		if (runtime_condition2) {
			auto y = C {};
			x.f() + y.f();
		} else {
			auto y = D {};
			x.f() + y.f();
		}
	} else {
		auto x = B{};
		if (runtime_condition2) {
			auto y = C {};
			x.f() + y.f();
		} else {
			auto y = D {};
			x.f() + y.f();
		}
	}

or to:

	variant<A, B> x;
	variant<C, D> y;
	bool hidden1 = runtime_condition1;
	if (hidden1)
		x.create<A>();
	else
		x.create<B>();
	bool hidden2 = runtime_condition2;
	if (hidden2)
		y.create<C>();
	else
		y.create<D>();
	if (hidden1) {
		if (hidden2)
			x.as<A>().f() + y.as<C>().f();
		else
			x.as<A>().f() + y.as<D>().f();
	} else {
		if (hidden2)
			x.as<B>().f() + y.as<C>().f();
		else
			x.as<B>().f() + y.as<D>().f();
	}

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1620864.HL4j5jKv18%40tjmaciei-mobl1.

.
