[PATCH] D16053: contains() convenience function
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 15 13:10:28 PST 2016
On Wed, Jan 13, 2016 at 11:12 AM, Alexander Droste <
alexander.ra.droste at googlemail.com> wrote:
> I tried:
>
> template <typename R, typename E>
> bool is_contained(R &&Range, const E &Element) {
> return any_of(Range, std::equal_to<E>(Element));
> }
>
> what does not work. Is another non std::equal_to implementation
> necessary in order to realize the is_contained function
> with equal_to?
Not sure I quite understand your question - is that producing a specific
compilation error message (could you copy/paste it)?
>
>
>
> On 11.01.16 18:12, David Blaikie wrote:
>
>>
>>
>> On Mon, Jan 11, 2016 at 9:09 AM, Benjamin Kramer <benny.kra at gmail.com
>> <mailto:benny.kra at gmail.com>> wrote:
>>
>> I have a slight preference for the equal_to solution because it's
>> standard C++14, but no strong opinion here.
>>
>>
>> Likewise - means not having to come up with another name, etc.
>>
>> Benjamin - did you want to implement an llvm::equal_to, or perhaps
>> Alexander can
>> instead of this patch?
>>
>>
>> On Mon, Jan 11, 2016 at 5:43 PM, David Blaikie <dblaikie at gmail.com
>> <mailto:dblaikie at gmail.com>> wrote:
>> > Benjamin and I were just discussing a similar piece of code to this
>> in a
>> > review
>> >
>> > I think we were settling on something like "any_of(R,
>> is_equal<>(E))" but
>> > I'm OK adding something like "contains" or "is_contained" (contains
>> seems
>> > like the right name, but might be too often used elsewhere to be
>> > convenient?)
>> >
>> > Benjamin - any thoughts/preferences here?
>> >
>> > On Mon, Jan 11, 2016 at 5:26 AM, Alexander Droste via llvm-commits
>> > <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>>
>> wrote:
>> >>
>> >> Alexander_Droste updated the summary for this revision.
>> >> Alexander_Droste added a reviewer: dblaikie.
>> >> Alexander_Droste updated this revision to Diff 44471.
>> >> Alexander_Droste added a comment.
>> >>
>> >> - changed name to `is_contained()` because `contains()` caused name
>> >> conflicts
>> >> - adapted the style of other functions in `STLExtras.h`
>> >>
>> >> - @David: I hope its ok that I added you as a reviewer. Googling
>> for
>> >> 'stlextras llvm reviewer' you
>> >>
>> >> were the first author that appeared.
>> >>
>> >>
>> >>http://reviews.llvm.org/D16053
>> >>
>> >> Files:
>> >> include/llvm/ADT/STLExtras.h
>> >>
>> >> Index: include/llvm/ADT/STLExtras.h
>> >> ===================================================================
>> >> --- include/llvm/ADT/STLExtras.h
>> >> +++ include/llvm/ADT/STLExtras.h
>> >> @@ -386,6 +386,13 @@
>> >> return std::find(Range.begin(), Range.end(), val);
>> >> }
>> >>
>> >> +/// Wrapper function around std::find to detect if an element
>> exists
>> >> +/// in a container.
>> >> +template <typename R, typename E>
>> >> +bool is_contained(R && Range, const E &Element) {
>> >> + return std::find(Range.begin(), Range.end(), Element) !=
>> Range.end();
>> >> +}
>> >> +
>> >>
>> >>
>> //===----------------------------------------------------------------------===//
>> >> // Extra additions to <memory>
>> >>
>> >>
>> //===----------------------------------------------------------------------===//
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> llvm-commits mailing list
>> >>llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
>> >>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>> >>
>> >
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160115/d9725213/attachment.html>
More information about the llvm-commits
mailing list