220 33507 <CAFk2RUaUTWj7xOz3aC-fDy754XYptA0U-SKtmSm+qn9pcek_Dw@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Ville Voutilainen <ville.voutilainen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Free function std::contains in algoritm and map
Date: Tue, 1 Aug 2017 20:29:22 +0300
Lines: 51
Approved: news@gmane.org
Message-ID: <CAFk2RUaUTWj7xOz3aC-fDy754XYptA0U-SKtmSm+qn9pcek_Dw@mail.gmail.com>
References: <b7cc5b96-2165-4b4d-a9d3-7ddec49ca626@isocpp.org> <CAFk2RUbMLLU6-zfnyFk_=FyAYU=cNNMCb=q6jijNf1Gr_FF+tQ@mail.gmail.com>
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 1501608564 11081 195.159.176.226 (1 Aug 2017 17:29:24 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 1 Aug 2017 17:29:24 +0000 (UTC)
To: "ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC5JHI7A7ALRB47UQLGAKGQE6Y6535A@isocpp.org Tue Aug 01 19:29:20 2017
Return-path: <std-proposals+bncBC5JHI7A7ALRB47UQLGAKGQE6Y6535A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f198.google.com ([209.85.161.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC5JHI7A7ALRB47UQLGAKGQE6Y6535A@isocpp.org>)
	id 1dcayt-0002bn-5Z
	for gclcip-std-proposals@m.gmane.org; Tue, 01 Aug 2017 19:29:19 +0200
Original-Received: by mail-yw0-f198.google.com with SMTP id t139sf35533127ywg.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Aug 2017 10:29:25 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1501608565; cv=pass;
        d=google.com; s=arc-20160816;
        b=hYUzk15f0xVKCpetU1pCmW2+XO+QlMqFhmV4SKKa6cdDxNlFHau+AWhdcssucY/HhB
         heU7TJYD8BzShc3vk4s9Bz1Q7pUIqqObZb8Lxq/8e/mU5uWeZi6/2zzO4w+izXZimtAf
         3wH0b5tndWHfvno8V2/hoXlAAAcX8Iy03QaovcAwvHgC52UjcQBpaUKH5ubugHjxa1KQ
         6SSVlxMG+MZrkcxvMGfYb2uHTUrnyBCzN9+6JE1bvL2ZrjPVSwDf98QEEVkyal5jaMrH
         nvqWca+OROm881CUoKgOuK1hn/p0UPbvgW0IyNmWJ+KNVRO9NJDkHe4eJNfi7wbdn+oT
         pW/A==
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:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=IILtv6ET3tFjR8yA83BrLrrw+Y8g9JJoNwiFVQqBaFY=;
        b=VaQV51xPOqmner4VLx2Y6MBNQ6GtL+IM+Am5rXtEIB36uZ96f/r3lI0Qfb+pwYs1Q7
         5Hs5/UuH3SRTnO77oKOyPYOUCqGgUwI4HM9IiHGwidU0RwG3sGU00P+T/e9GSpgMjdl7
         gXXZd28LQVn3s4cdGhgmwS6ZOAkQzJm+aw14AqvqwYY0i0cHH4Zt/49bWwlRNeveqSJ9
         BcXRRTpppx/vCWl2VaRcnfCWHLXf+mT3ExZInuPyV3w6xNJakV9rrE3ob08+o6PUB3dw
         2iqU6j56KFPTqVPCpAp79bqFS+eTy5xSQ+QlPKWVhpoKJ574IbfwEgQgQUJKKuQLk2sJ
         tYGA==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=Wuh+xVCT;
       spf=pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:400c:c05::244 as permitted sender) smtp.mailfrom=ville.voutilainen@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject: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;
        bh=IILtv6ET3tFjR8yA83BrLrrw+Y8g9JJoNwiFVQqBaFY=;
        b=J+18SDU5PAZRvQsILT7/Bqe6/oiN1fRuC5D+EYoZeTr8I1hIYhNfQAHV4UYB/m/kvi
         uJTcKU/ztFQu/7O/J1q1vVXPx5xRgu3b8vScBT2xyozxAcXUwVZdaPmqfSryBvVQcHWq
         nxsye0WontVi414BoRtkp4dS8Jvs39jDAxgoIDK+y6lIVhKxthAo7XnQtp9WW5qS0Wn3
         g9QgfS1rESEt+R1PFXTtT/PX71cHrACu9/bC3TnCIupFpaokBU6cEwa9AeUSLvWNJOyb
         SOaPzC1mbVDbmg//8qWJGTnree9IEBpGQimFvPeuCMBhNNktYf+HxVjwMJNtztCas9iz
         ZBSg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to: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=IILtv6ET3tFjR8yA83BrLrrw+Y8g9JJoNwiFVQqBaFY=;
        b=HhOVt/a5hwzZiEeQFipyjGMqGtKQ0Pr6/uILS2E8uLnqeFSNEAG9gWuHB4P4bNkk7K
         6jl4ew8LIYPs6eanWu2aoQlTIK0E0voLTz+poakqGeh3pUVD6HtW2gG6MLatGpu9RO1Y
         8ePlz61ItThkmRn540F96IfX753UFJBcbHa7pPcLsMzJH8mynEK2Za4c4X3oDkNrCvvp
         Vn8QuN5FKrfueEH+jVRJCZyPh8dpdfRk5mthH0Db7mAtpy25HIBJJuK2H8vQiAZY/Q6O
         ybxhEFKTfshMEIYfraYGvLbPUn4HzuHn+j3sjQN2s4W77bBPf8Q28sFq7JyQFjXvZ1I0
         kKCw==
X-Gm-Message-State: AIVw1113krY4NTmM21kTtC9GZjy/s5saZMLH7g1tyh11mFRYFAlE6ybM
	Rv4LZGoa4XhKDCnu
X-Received: by 10.129.94.138 with SMTP id s132mr11223269ywb.87.1501608565060;
        Tue, 01 Aug 2017 10:29:25 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.86.145 with SMTP id o139ls1461250itb.20.gmail; Tue, 01 Aug
 2017 10:29:23 -0700 (PDT)
X-Received: by 10.176.85.11 with SMTP id t11mr4377948uaa.132.1501608563783;
        Tue, 01 Aug 2017 10:29:23 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501608563; cv=none;
        d=google.com; s=arc-20160816;
        b=d0u1a2weVN8d40bbsOpBVYakuKBHG/9+hLJjnHqbofBugwSUB4msWE4CkfVxFbKWCb
         N5nqow8lIRy9qC3+bdkxn7wd8ok2aisXDp1oxbkSO0NchinNghGHlcafcgx5DZCNDMBW
         aRwt+Y9WSzJ1D9O14FO6lOkYUBO0YF/NCaX6QewXpzeP+fNNS44cVr7aN1PLj+wwfbeA
         h4Ra5JlXJDRsE6Jj/T/RJYy1/EUj6FQJ56oRA4OQUJzjLnvGgt5UjhQJQEttMPCNgdoC
         +67h07Y9gmrywyzbvjJUfNofrT1vXAq7kbs+19UjXcmiX8/UmqFzncLayC/4tlHjot0I
         BPQA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=1hxEJz7LoXsPUaCoVe1D2zvmTY/vViaQngq5eBFcO1o=;
        b=bka/HaX1Y06BUlyx6QcHq9tGYKTgE7uoLAlygkkhk/C1yywXjl2YfdE3EEnFoIt+XW
         nbJQCYoSEZg4zf6YS9hUq8hUIP0VgNbo+PI+lPIQj5AOFWZS+OQjVaK3QFqwAlJCqYEt
         YONPSxFzoytkxhjCqNcbfkOGERaEtGtKQ3Mb40xvm6RdlzwVK4VYcMHt34Xox/iXYxoM
         eMIvtw63L5F4nchnAwjDZsgheHZpA+2EzUzma/m4IsAmpKTYXajHOreRIuVW4Uy0n7j6
         nEqz+eBJF0KhyKTYY/ipJa2btT3isvYsA9Kzr3nL4LB7sWrpvVmsk1aj1H1hdNp3FRFo
         xqmQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=Wuh+xVCT;
       spf=pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:400c:c05::244 as permitted sender) smtp.mailfrom=ville.voutilainen@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-vk0-x244.google.com (mail-vk0-x244.google.com. [2607:f8b0:400c:c05::244])
        by mx.google.com with ESMTPS id i37si14920002uag.363.2017.08.01.10.29.23
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 01 Aug 2017 10:29:23 -0700 (PDT)
Received-SPF: pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:400c:c05::244 as permitted sender) client-ip=2607:f8b0:400c:c05::244;
Original-Received: by mail-vk0-x244.google.com with SMTP id x10so1081240vkd.2
        for <std-proposals@isocpp.org>; Tue, 01 Aug 2017 10:29:23 -0700 (PDT)
X-Received: by 10.31.206.133 with SMTP id e127mr9037420vkg.145.1501608563431;
 Tue, 01 Aug 2017 10:29:23 -0700 (PDT)
Original-Received: by 10.103.103.65 with HTTP; Tue, 1 Aug 2017 10:29:22 -0700 (PDT)
In-Reply-To: <CAFk2RUbMLLU6-zfnyFk_=FyAYU=cNNMCb=q6jijNf1Gr_FF+tQ@mail.gmail.com>
X-Original-Sender: ville.voutilainen@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=Wuh+xVCT;       spf=pass (google.com: domain of
 ville.voutilainen@gmail.com designates 2607:f8b0:400c:c05::244 as permitted
 sender) smtp.mailfrom=ville.voutilainen@gmail.com;       dmarc=pass (p=NONE
 sp=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: <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:33507
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33507>

On 1 August 2017 at 20:26, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 1 August 2017 at 20:22,  <david.bolvansky@gmail.com> wrote:
>> Instead of comparing with end(), there could be a new function - contains.
>>
>> Now
>>
>> if(std::find(vector.begin(), vector.end(), item) != vector.end()){
>>     // found
>> } else {
>>     // not found
>> }
>>
>>  // maps
>>
>> if(map.find("key") != map.end()){
>>     // found
>> } else {
>>     // not found
>> }
>>
>>
>>
>> I propose "contains" function:
>>
>> if(std::contains(vector.begin(), vector.end(), item)){
>>     // found
>> } else {
>>     // not found
>> }
>>
>>  // maps
>>
>> if(map.contains("key")){
>>     // found
>> } else {
>>     // not found
>> }
>
>
> Just use std::count and map::count.

...well, except that wastes cycles since it won't stop before the end
of the range for vector.

-- 
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/CAFk2RUaUTWj7xOz3aC-fDy754XYptA0U-SKtmSm%2Bqn9pcek_Dw%40mail.gmail.com.

.
