[PATCH] D17311: allow lambdas in mapped_iterator
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 16:27:32 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL263759: allow lambdas in mapped_iterator (authored by aizatsky).
Changed prior to commit:
http://reviews.llvm.org/D17311?vs=50884&id=50987#toc
Repository:
rL LLVM
http://reviews.llvm.org/D17311
Files:
llvm/trunk/include/llvm/ADT/STLExtras.h
llvm/trunk/unittests/ADT/CMakeLists.txt
llvm/trunk/unittests/ADT/MappedIteratorTest.cpp
Index: llvm/trunk/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h
+++ llvm/trunk/include/llvm/ADT/STLExtras.h
@@ -117,7 +117,7 @@
iterator_category;
typedef typename std::iterator_traits<RootIt>::difference_type
difference_type;
- typedef typename UnaryFunc::result_type value_type;
+ typedef decltype(Fn(*current)) value_type;
typedef void pointer;
//typedef typename UnaryFunc::result_type *pointer;
Index: llvm/trunk/unittests/ADT/CMakeLists.txt
===================================================================
--- llvm/trunk/unittests/ADT/CMakeLists.txt
+++ llvm/trunk/unittests/ADT/CMakeLists.txt
@@ -22,6 +22,7 @@
IntervalMapTest.cpp
IntrusiveRefCntPtrTest.cpp
MakeUniqueTest.cpp
+ MappedIteratorTest.cpp
MapVectorTest.cpp
OptionalTest.cpp
PackedVectorTest.cpp
Index: llvm/trunk/unittests/ADT/MappedIteratorTest.cpp
===================================================================
--- llvm/trunk/unittests/ADT/MappedIteratorTest.cpp
+++ llvm/trunk/unittests/ADT/MappedIteratorTest.cpp
@@ -0,0 +1,51 @@
+//===- llvm/unittest/ADT/APInt.cpp - APInt unit tests ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <vector>
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/iterator_range.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+template <class T, class Fn>
+auto map_range(const T &range, Fn fn)
+ -> decltype(make_range(map_iterator(range.begin(), fn),
+ map_iterator(range.end(), fn))) {
+ return make_range(map_iterator(range.begin(), fn),
+ map_iterator(range.end(), fn));
+}
+
+static char add1(char C) { return C + 1; }
+
+TEST(MappedIterator, FnTest) {
+ std::string S("abc");
+ std::string T;
+
+ for (char C : map_range(S, add1)) {
+ T.push_back(C);
+ }
+
+ EXPECT_STREQ("bcd", T.c_str());
+}
+
+TEST(MappedIterator, LambdaTest) {
+ std::string S("abc");
+ std::string T;
+
+ for (char C : map_range(S, [](char C) { return C + 1; })) {
+ T.push_back(C);
+ }
+
+ EXPECT_STREQ("bcd", T.c_str());
+}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17311.50987.patch
Type: text/x-patch
Size: 2419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160317/0989d4f6/attachment.bin>
More information about the llvm-commits
mailing list