[cfe-commits] [libcxx] r111278 - in /libcxx/trunk: include/ test/re/re.iter/re.tokiter/ test/re/re.iter/re.tokiter/re.tokiter.cnstr/ test/re/re.iter/re.tokiter/re.tokiter.comp/ test/re/re.iter/re.tokiter/re.tokiter.deref/ test/re/re.iter/re.tokiter/re.tokiter.incr/

Howard Hinnant hhinnant at apple.com
Tue Aug 17 13:42:03 PDT 2010


Author: hhinnant
Date: Tue Aug 17 15:42:03 2010
New Revision: 111278

URL: http://llvm.org/viewvc/llvm-project?rev=111278&view=rev
Log:
[re.tokiter]

Added:
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp
    libcxx/trunk/test/re/re.iter/re.tokiter/types.pass.cpp
Modified:
    libcxx/trunk/include/regex

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=111278&r1=111277&r2=111278&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Tue Aug 17 15:42:03 2010
@@ -6038,33 +6038,234 @@
     typedef const value_type&                 reference;
     typedef forward_iterator_tag              iterator_category;
 
+private:
+    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
+
+    _Position         __position_;
+    const value_type* __result_;
+    value_type        __suffix_;
+    ptrdiff_t         _N_;
+    vector<int>       __subs_;
+
+public:
     regex_token_iterator();
     regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
                          const regex_type& __re, int __submatch = 0,
-                         regex_constants::match_flag_type __m = regex_constants::match_default);
+                         regex_constants::match_flag_type __m =
+                                                regex_constants::match_default);
     regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
                          const regex_type& __re, const vector<int>& __submatches,
-                         regex_constants::match_flag_type __m = regex_constants::match_default);
+                         regex_constants::match_flag_type __m =
+                                                regex_constants::match_default);
     regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
-                         const regex_type& __re, initializer_list<int> __submatches,
-                         regex_constants::match_flag_type __m = regex_constants::match_default);
+                         const regex_type& __re,
+                         initializer_list<int> __submatches,
+                         regex_constants::match_flag_type __m =
+                                                regex_constants::match_default);
     template <size_t _N>
-        regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
-                             const regex_type& __re, const int (&__submatches)[_N],
-                             regex_constants::match_flag_type __m = regex_constants::match_default);
+        regex_token_iterator(_BidirectionalIterator __a,
+                             _BidirectionalIterator __b,
+                             const regex_type& __re,
+                             const int (&__submatches)[_N],
+                             regex_constants::match_flag_type __m =
+                                                regex_constants::match_default);
     regex_token_iterator(const regex_token_iterator&);
     regex_token_iterator& operator=(const regex_token_iterator&);
 
-    bool operator==(const regex_token_iterator&) const;
-    bool operator!=(const regex_token_iterator&) const;
+    bool operator==(const regex_token_iterator& __x) const;
+    bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
 
-    const value_type& operator*() const;
-    const value_type* operator->() const;
+    const value_type& operator*() const {return *__result_;}
+    const value_type* operator->() const {return __result_;}
 
     regex_token_iterator& operator++();
-    regex_token_iterator operator++(int);
+    regex_token_iterator operator++(int)
+    {
+        regex_token_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+private:
+    void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
 };
 
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator()
+    : __result_(nullptr),
+      __suffix_(),
+      _N_(0)
+{
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+void
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
+{
+    if (__position_ != _Position())
+    {
+        if (__subs_[_N_] == -1)
+            __result_ = &__position_->prefix();
+        else
+            __result_ = &(*__position_)[__subs_[_N_]];
+    }
+    else if (__subs_[_N_] == -1)
+    {
+        __suffix_.matched = true;
+        __suffix_.first = __a;
+        __suffix_.second = __b;
+        __result_ = &__suffix_;
+    }
+    else
+        __result_ = nullptr;
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type& __re, int __submatch,
+                         regex_constants::match_flag_type __m)
+    : __position_(__a, __b, __re, __m),
+      _N_(0),
+      __subs_(1, __submatch)
+{
+    __init(__a, __b);
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type& __re, const vector<int>& __submatches,
+                         regex_constants::match_flag_type __m)
+    : __position_(__a, __b, __re, __m),
+      _N_(0),
+      __subs_(__submatches)
+{
+    __init(__a, __b);
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type& __re,
+                         initializer_list<int> __submatches,
+                         regex_constants::match_flag_type __m)
+    : __position_(__a, __b, __re, __m),
+      _N_(0),
+      __subs_(__submatches)
+{
+    __init(__a, __b);
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+template <size_t _N>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                             const regex_type& __re,
+                             const int (&__submatches)[_N],
+                             regex_constants::match_flag_type __m)
+    : __position_(__a, __b, __re, __m),
+      _N_(0),
+      __subs_(__submatches, __submatches + _N)
+{
+    __init(__a, __b);
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    regex_token_iterator(const regex_token_iterator& __x)
+    : __position_(__x.__position_),
+      __result_(__x.__result_),
+      __suffix_(__x.__suffix_),
+      _N_(__x._N_),
+      __subs_(__x.__subs_)
+{
+    if (__x.__result_ == &__x.__suffix_)
+        __result_ == &__suffix_;
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    operator=(const regex_token_iterator& __x)
+{
+    if (this != &__x)
+    {
+        __position_ = __x.__position_;
+        if (__x.__result_ == &__x.__suffix_)
+            __result_ == &__suffix_;
+        else
+            __result_ = __x.__result_;
+        __suffix_ = __x.__suffix_;
+        _N_ = __x._N_;
+        __subs_ = __x.__subs_;
+    }
+    return *this;
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+bool
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
+    operator==(const regex_token_iterator& __x) const
+{
+    if (__result_ == nullptr && __x.__result_ == nullptr)
+        return true;
+    if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
+            __suffix_ == __x.__suffix_)
+        return true;
+    if (__result_ == nullptr || __x.__result_ == nullptr)
+        return false;
+    if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
+        return false;
+    return __position_ == __x.__position_ && _N_ == __x._N_ &&
+           __subs_ == __x.__subs_;
+}
+
+template <class _BidirectionalIterator, class _CharT, class _Traits>
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
+regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
+{
+    _Position __prev = __position_;
+    if (__result_ == &__suffix_)
+        __result_ = nullptr;
+    else if (_N_ + 1 < __subs_.size())
+    {
+        ++_N_;
+        if (__subs_[_N_] == -1)
+            __result_ = &__position_->prefix();
+        else
+            __result_ = &(*__position_)[__subs_[_N_]];
+    }
+    else
+    {
+        _N_ = 0;
+        ++__position_;
+        if (__position_ != _Position())
+        {
+            if (__subs_[_N_] == -1)
+                __result_ = &__position_->prefix();
+            else
+                __result_ = &(*__position_)[__subs_[_N_]];
+        }
+        else
+        {
+            if (_STD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
+                && __prev->suffix().length() != 0)
+            {
+                __suffix_.matched = true;
+                __suffix_.first = __prev->suffix().first;
+                __suffix_.second = __prev->suffix().second;
+                __result_ = &__suffix_;
+            }
+            else
+                __result_ = nullptr;
+        }
+    }
+    return *this;
+}
+
 typedef regex_token_iterator<const char*>             cregex_token_iterator;
 typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
 typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// template <size_t N>
+// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+//                      const regex_type& re,
+//                      const int (&submatches)[N],
+//                      regex_constants::match_flag_type m =
+//                                              regex_constants::match_default);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        const int indices[] = {-1, 0, 1};
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, indices);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// regex_token_iterator();
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test()
+{
+    typedef std::regex_token_iterator<const CharT*> I;
+    I i1;
+    assert(i1 == I());
+}
+
+int main()
+{
+    test<char>();
+    test<wchar_t>();
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+//                      const regex_type& re,
+//                      initializer_list<int> submatches,
+//                      regex_constants::match_flag_type m =
+//                                              regex_constants::match_default);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, {-1, 0, 1});
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+#endif
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+//                      const regex_type& re, int submatch = 0,
+//                      regex_constants::match_flag_type m =
+//                                              regex_constants::match_default);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, -1);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, 1);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "3456");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,128 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+//                      const regex_type& re,
+//                      const std::vector<int>& submatches,
+//                      regex_constants::match_flag_type m =
+//                                              regex_constants::match_default);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::vector<int> v;
+        v.push_back(-1);
+        v.push_back(-1);
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, v);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::vector<int> v;
+        v.push_back(-1);
+        v.push_back(0);
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, v);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::vector<int> v;
+        v.push_back(-1);
+        v.push_back(0);
+        v.push_back(1);
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, v);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "3456");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// bool operator==(const regex_token_iterator& right) const;
+// bool operator!=(const regex_token_iterator& right) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, -1);
+        assert(i != std::cregex_token_iterator());
+        assert(!(i == std::cregex_token_iterator()));
+        std::cregex_token_iterator i2 = i;
+        assert(i2 == i);
+        assert(!(i2 != i));
+        ++i;
+        assert(!(i2 == i));
+        assert(i2 != i);
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// const value_type& operator*() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, -1);
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "start ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == ", ");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == " end");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers);
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "555-1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "555-2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "555-3456");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, 1);
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "1234");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "2345");
+        ++i;
+        assert(i != std::cregex_token_iterator());
+        assert((*i).str() == "3456");
+        ++i;
+        assert(i == std::cregex_token_iterator());
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class regex_token_iterator<BidirectionalIterator, charT, traits>
+
+// regex_token_iterator& operator++(int);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, -1);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "start ");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == ", ");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == " end");
+        i++;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-\\d{4}");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-1234");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-2345");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "555-3456");
+        i++;
+        assert(i == std::cregex_token_iterator());
+    }
+    {
+        std::regex phone_numbers("\\d{3}-(\\d{4})");
+        const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+        std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book),
+                                     phone_numbers, 1);
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "1234");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "2345");
+        i++;
+        assert(i != std::cregex_token_iterator());
+        assert(i->str() == "3456");
+        i++;
+        assert(i == std::cregex_token_iterator());
+    }
+}
\ No newline at end of file

Added: libcxx/trunk/test/re/re.iter/re.tokiter/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.iter/re.tokiter/types.pass.cpp?rev=111278&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.iter/re.tokiter/types.pass.cpp (added)
+++ libcxx/trunk/test/re/re.iter/re.tokiter/types.pass.cpp Tue Aug 17 15:42:03 2010
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator,
+//           class charT = typename iterator_traits< BidirectionalIterator>::value_type,
+//           class traits = regex_traits<charT>>
+// class regex_token_iterator
+// {
+// public:
+//     typedef basic_regex<charT, traits>       regex_type;
+//     typedef sub_match<BidirectionalIterator> value_type;
+//     typedef ptrdiff_t                        difference_type;
+//     typedef const value_type*                pointer;
+//     typedef const value_type&                reference;
+//     typedef forward_iterator_tag             iterator_category;
+
+#include <regex>
+#include <type_traits>
+
+template <class CharT>
+void
+test()
+{
+    typedef std::regex_token_iterator<const CharT*> I;
+    static_assert((std::is_same<typename I::regex_type, std::basic_regex<CharT> >::value), "");
+    static_assert((std::is_same<typename I::value_type, std::sub_match<const CharT*> >::value), "");
+    static_assert((std::is_same<typename I::difference_type, std::ptrdiff_t>::value), "");
+    static_assert((std::is_same<typename I::pointer, const std::sub_match<const CharT*>*>::value), "");
+    static_assert((std::is_same<typename I::reference, const std::sub_match<const CharT*>&>::value), "");
+    static_assert((std::is_same<typename I::iterator_category, std::forward_iterator_tag>::value), "");
+}
+
+int main()
+{
+    test<char>();
+    test<wchar_t>();
+}
\ No newline at end of file





More information about the cfe-commits mailing list