220 8063 <52A4065B.2010806@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Subsets of constexpr functions should be
 considered constant expressions (in certain cases)
Date: Sun, 08 Dec 2013 13:40:43 +0800
Lines: 52
Approved: news@gmane.org
Message-ID: <52A4065B.2010806@gmail.com>
References: <8c654488-9a6d-4d14-ae94-c854bf9fcf8b@isocpp.org>
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
X-Trace: ger.gmane.org 1386481246 32239 80.91.229.3 (8 Dec 2013 05:40:46 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 8 Dec 2013 05:40:46 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBYEMSCKQKGQEFISZJKI@isocpp.org Sun Dec 08 06:40:52 2013
Return-path: <std-proposals+bncBCW25A7E3QCRBYEMSCKQKGQEFISZJKI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f197.google.com ([209.85.192.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBYEMSCKQKGQEFISZJKI@isocpp.org>)
	id 1VpX6p-0002Vz-CI
	for gclcip-std-proposals@m.gmane.org; Sun, 08 Dec 2013 06:40:51 +0100
Original-Received: by mail-pd0-f197.google.com with SMTP id v10sf11244694pde.4
        for <gclcip-std-proposals@m.gmane.org>; Sat, 07 Dec 2013 21:40:49 -0800 (PST)
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;
        bh=KbZSgoLE5C8sd6uly1t8WBWGk2m4bM9k4L/zxHG8Jc4=;
        b=dNNd2I7XuR7ZoxDdW0pqcvflhLNUZQV0dxBdg11WRIFuYpMpY8S5HQ2Z397xPBOSqv
         t7gcD3bWcgvXRAFKnEqIr7t1uajZHI7y9Xd8Z1Axo9fyFowKrKgu4GKizdM8gKJPvmFb
         +JJWwygp/G2jxaRWXOcT2vXG43mZR12ptL8p22XAsCszKEdwYD+D2q/aYHKhFC82BYK6
         xgEdzQhFdJ2b98+pcFkYVk6hCW6cljEKEpasG5nT7+7HB0w3tfQ4kSjYB0UZc7/s9CYA
         xtDEzwOeFXPSHBi6y/3cTvfPuNVqRhDsP9rmcTTb1s7Uqv1QK6o+sJrW48QNJ1/uSWBU
         7U+A==
X-Gm-Message-State: ALoCoQk78TZfKBWzy9ESTseoLeb6IJFzpjFsHuiUry8DhFMPPl3t0eaCe0ByLgDcIKy617sYLIVP
X-Received: by 10.67.3.34 with SMTP id bt2mr94909pad.41.1386481249218;
        Sat, 07 Dec 2013 21:40:49 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.58.229 with SMTP id u5ls1820701qeq.69.gmail; Sat, 07 Dec
 2013 21:40:48 -0800 (PST)
X-Received: by 10.236.220.195 with SMTP id o63mr580877yhp.149.1386481248393;
        Sat, 07 Dec 2013 21:40:48 -0800 (PST)
Original-Received: from mail-pb0-x236.google.com (mail-pb0-x236.google.com [2607:f8b0:400e:c01::236])
        by mx.google.com with ESMTPS id k1si4502302yhm.118.2013.12.07.21.40.48
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 07 Dec 2013 21:40:48 -0800 (PST)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c01::236 as permitted sender) client-ip=2607:f8b0:400e:c01::236;
Original-Received: by mail-pb0-f54.google.com with SMTP id un15so3421504pbc.13
        for <std-proposals@isocpp.org>; Sat, 07 Dec 2013 21:40:47 -0800 (PST)
X-Received: by 10.66.218.226 with SMTP id pj2mr13478073pac.62.1386481247548;
        Sat, 07 Dec 2013 21:40:47 -0800 (PST)
Original-Received: from Davids-MacBook-Pro.local ([121.54.54.152])
        by mx.google.com with ESMTPSA id nn6sm8529800pbc.29.2013.12.07.21.40.44
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 07 Dec 2013 21:40:46 -0800 (PST)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To: <8c654488-9a6d-4d14-ae94-c854bf9fcf8b@isocpp.org>
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c01::236 as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
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:8063
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8063>

On 12/7/13 12:31 PM, Mark wrote:
> I've been toying around with the relaxed constexpr rules of C++14 in an SVN
> build of clang. The thought occurred to me that I might be able to use the
> 'natural' syntax of a for loop to iterate over the contents in a std::tuple
> at compile-time in a constexpr function.

Currently, each name is declared once with a definite type, and looked 
up exactly once per use, or once per template instantiation in the case 
of names following a template argument dependent nested-name-specifier. 
Resolving a new type for a local name once per loop iteration would be 
quite a radical change.

The most similar proposal is called static_if, to allow a section of 
source code to be interpreted either zero or one times. Static loops are 
a logical next step. The idea is very controversial, and it's not clear 
that such a construct is conducive to type-safe generic programming. 
(The main problem is that it attempts to ignore scoping, which your idea 
doesn't require.)

The for_each idiom is doable in C++14 using the limited local template 
facility in polymorphic lambdas.

template< typename tuple, typename ftor, std::size_t ... index >
void tuple_for_each_impl( tuple & t, ftor f, std::integer_sequence< 
std::size_t, index ... > ) {
     int q[] = { ( f( std::get< index >( t ) ), 0 ) ... };
}

template< typename tuple, typename ftor >
void tuple_for_each( tuple && t, ftor f ) {
     tuple_for_each_impl( t, std::move( f ),
         std::make_integer_sequence< std::size_t, std::tuple_size< 
typename std::decay< tuple >::type >::value >()
     );
}

tuple_for_each(
     std::make_tuple( "Hello ", true, std::string( " world!" ), 1 ),
     []( auto x ) { std::cout << x; }
);

(I was not able to test this because my GCC doesn't have 
make_integer_sequence and my Clang doesn't have polymorphic lambdas.)

-- 

--- 
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/.

.
