[PATCH] D16053: is_contained() convenience function
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 17 13:40:39 PST 2016
I think in the last review I/we were just suggesting to use any_of +
equal_to directly & skip adding this extra construct entirely.
In any case, std::equal_to is a C++14 feature, so we probably can't use it
in LLVM & the suggestion/discussion was about whether we could/should just
implement one in LLVM (llvm::equal_to). But you also make a good point
about equal_to needing a parameter/binding, blah blah - Ben: thoughts on
that? Still nice if we have to use bind too? Could/should we make another
function object to handle that more easily (the general case of a stateful
unary equal_to, I mean)?
On Sun, Jan 17, 2016 at 1:28 PM, Alexander Droste via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Alexander_Droste retitled this revision from "contains() convenience
> function" to "is_contained() convenience function".
> Alexander_Droste updated this revision to Diff 45115.
> Alexander_Droste added a comment.
>
> - changed implementation to `std::equal_to<>` style
>
>
> 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 llvm::any_of to detect if an element exists
> +/// in a container.
> +template <typename R, typename E>
> +bool is_contained(R &&Range, const E &Element) {
> + return any_of(Range, bind2nd(std::equal_to<E>(), Element));
> +}
> +
>
> //===----------------------------------------------------------------------===//
> // Extra additions to <memory>
>
> //===----------------------------------------------------------------------===//
>
>
>
> _______________________________________________
> llvm-commits mailing list
> 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/20160117/69f23c62/attachment.html>
More information about the llvm-commits
mailing list