[cfe-commits] [libcxx] r107187 - in /libcxx/trunk: include/ test/re/re.regex/re.regex.construct/ test/re/re.submatch/ test/re/re.submatch/re.submatch.members/ test/re/re.submatch/re.submatch.op/

Howard Hinnant hhinnant at apple.com
Tue Jun 29 11:37:43 PDT 2010


Author: hhinnant
Date: Tue Jun 29 13:37:43 2010
New Revision: 107187

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

Added:
    libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.members/length.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.members/operator_string.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.members/str.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.op/compare.pass.cpp
    libcxx/trunk/test/re/re.submatch/re.submatch.op/stream.pass.cpp
    libcxx/trunk/test/re/re.submatch/types.pass.cpp
Modified:
    libcxx/trunk/include/regex
    libcxx/trunk/test/re/re.regex/re.regex.construct/ptr_flg.pass.cpp

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=107187&r1=107186&r2=107187&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Tue Jun 29 13:37:43 2010
@@ -721,6 +721,9 @@
 #include <stdexcept>
 #include <__locale>
 #include <initializer_list>
+#include <utility>
+#include <iterator>
+#include <string>
 
 #pragma GCC system_header
 
@@ -1209,6 +1212,114 @@
     return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
 }
 
+template <class _CharT> class __transition;
+
+template <class _CharT>
+class __state
+{
+    typedef __transition<_CharT> __transition;
+    __transition* __t1_;
+    __transition* __t2_;
+    int __state_;
+    enum
+    {
+        __1_not_tried = 0,
+        __1_succeded = 1,
+        __1_failed = 2,
+        __2_not_tried = 0,
+        __2_succeded = 4,
+        __2_failed = 8
+    };
+
+    __state(const __state&);
+    __state& operator=(const __state&);
+public:
+    __state()
+        : __t1_(), __t2_(), __state_() {}
+    ~__state();
+
+    const __state* operator()(_CharT __c);
+
+    void __add_one(__transition* __t) {__t1_ = __t;}
+};
+
+template <class _CharT>
+__state<_CharT>::~__state()
+{
+    delete __t1_;
+    delete __t2_;
+}
+
+template <class _CharT>
+const __state<_CharT>*
+__state<_CharT>::operator()(_CharT __c)
+{
+    const __state* __r = nullptr;
+    if ((__state_ & 3) == 0)
+    {
+        if (__t1_)
+        {
+            __r = (*__t1_)(__c);
+            if (__r)
+                __state_ |= __1_succeded;
+            else
+                __state_ |= __1_failed;
+        }
+        else
+            __state_ |= __1_failed;
+    }
+    else if ((__state_ & 0xC) == 0)
+    {
+        if (__t2_)
+        {
+            __r = (*__t2_)(__c);
+            if (__r)
+                __state_ |= __2_succeded;
+            else
+                __state_ |= __2_failed;
+        }
+        else
+            __state_ |= __2_failed;
+    }
+    return __r;
+}
+
+template <class _CharT>
+class __transition
+{
+    __transition(const __transition&);
+    __transition& operator=(const __transition&);
+
+    typedef __state<_CharT> __state;
+    typedef unique_ptr<__state, void(*)(__state*)> __sptr;
+
+    static void __delete_state(__state* __p) {delete __p;}
+    static void __ignore_state(__state*) {}
+
+protected:
+    __sptr __sptr_;
+public:
+    __transition(bool __owns, __state* __st)
+        : __sptr_(__st, __owns ? &__delete_state : &__ignore_state) {}
+    virtual ~__transition() {}
+
+    virtual const __state* operator()(_CharT) const {return __sptr_.get();}
+};
+
+template <class _CharT>
+class __match_char
+    : public __transition<_CharT>
+{
+    typedef __transition<_CharT> base;
+    _CharT __c_;
+public:
+    __match_char(_CharT __c, bool __owns, __state<_CharT>* __st)
+        : base(__owns, __st), __c_(__c) {}
+
+    virtual const __state<_CharT>* operator()(_CharT __c) const
+        {return __c == __c_ ? base::__sptr_.get() : nullptr;}
+};
+
 template <class _CharT, class _Traits = regex_traits<_CharT> >
 class basic_regex
 {
@@ -1222,6 +1333,9 @@
     _Traits   __traits_;
     flag_type __flags_;
     unsigned __marked_count_;
+    int __open_count_;
+    shared_ptr<__state<_CharT> > __start_;
+    __state<_CharT>* __end_;
 
 public:
     // constants:
@@ -1239,10 +1353,10 @@
     // construct/copy/destroy:
     basic_regex();
     explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
-        : __flags_(__f), __marked_count_(0)
+        : __flags_(__f), __marked_count_(0), __open_count_(0), __end_(0)
         {__parse(__p, __p + __traits_.length(__p));}
     basic_regex(const value_type* __p, size_t __len, flag_type __f)
-        : __flags_(__f), __marked_count_(0)
+        : __flags_(__f), __marked_count_(0), __open_count_(0), __end_(0)
         {__parse(__p, __p + __len);}
     basic_regex(const basic_regex&);
 #ifdef _LIBCPP_MOVE
@@ -1251,16 +1365,16 @@
     template <class _ST, class _SA>
         explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
                              flag_type __f = regex_constants::ECMAScript)
-        : __flags_(__f), __marked_count_(0)
+        : __flags_(__f), __marked_count_(0), __open_count_(0), __end_(0)
         {__parse(__p.begin(), __p.end());}
     template <class _ForwardIterator>
         basic_regex(_ForwardIterator __first, _ForwardIterator __last,
                     flag_type __f = regex_constants::ECMAScript)
-        : __flags_(__f), __marked_count_(0)
+        : __flags_(__f), __marked_count_(0), __open_count_(0), __end_(0)
         {__parse(__first, __last);}
     basic_regex(initializer_list<value_type> __il,
                 flag_type __f = regex_constants::ECMAScript)
-        : __flags_(__f), __marked_count_(0)
+        : __flags_(__f), __marked_count_(0), __open_count_(0), __end_(0)
         {__parse(__il.begin(), __il.end());}
 
     ~basic_regex();
@@ -1345,6 +1459,9 @@
         __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last);
     template <class _ForwardIterator>
         _ForwardIterator
+        __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
         __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
     template <class _ForwardIterator>
         _ForwardIterator
@@ -1364,6 +1481,24 @@
     template <class _ForwardIterator>
         _ForwardIterator
         __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
+    template <class _ForwardIterator>
+        _ForwardIterator
+        __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
 
     void __push_l_anchor() {}
     void __push_r_anchor() {}
@@ -1375,11 +1510,12 @@
     void __start_matching_list() {}
     void __end_nonmatching_list() {}
     void __end_matching_list() {}
-    void __push_char(value_type __c) {}
+    void __push_char(value_type __c);
     void __push_char(const typename _Traits::string_type& __c) {}
     void __push_range() {}
     void __push_class_type(typename _Traits::char_class_type) {}
     void __push_back_ref(int __i) {}
+    void __push_alternation() {}
 };
 
 template <class _CharT, class _Traits>
@@ -1408,6 +1544,7 @@
         __parse_basic_reg_exp(__first, __last);
         break;
     case extended:
+        __parse_extended_reg_exp(__first, __last);
         break;
     case awk:
         break;
@@ -1455,6 +1592,81 @@
 template <class _CharT, class _Traits>
 template <class _ForwardIterator>
 _ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
+                                                       _ForwardIterator __last)
+{
+    while (true)
+    {
+        _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
+        if (__temp == __first)
+            throw regex_error(regex_constants::error_temp);
+        __first = __temp;
+        if (__first == __last)
+            break;
+        if (*__first != '|')
+            throw regex_error(regex_constants::error_temp);
+        __push_alternation();
+        ++__first;
+    }
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
+                                                 _ForwardIterator __last)
+{
+    _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
+    if (__temp == __first)
+        throw regex_error(regex_constants::error_temp);
+    do
+    {
+        __first = __temp;
+        __temp = __parse_ERE_expression(__first, __last);
+    } while (__temp != __first);
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
+                                                     _ForwardIterator __last)
+{
+    _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
+    if (__temp == __first && __temp != __last)
+    {
+        switch (*__temp)
+        {
+        case '^':
+            __push_l_anchor();
+            ++__temp;
+            break;
+        case '$':
+            __push_r_anchor();
+            ++__temp;
+            break;
+        case '(':
+            ++__marked_count_;
+            ++__open_count_;
+            __temp = __parse_extended_reg_exp(++__temp, __last);
+            if (__temp == __last || *__temp != ')')
+                throw regex_error(regex_constants::error_paren);
+            --__open_count_;
+            ++__temp;
+            break;
+        }
+    }
+    if (__temp != __first)
+        __temp = __parse_ERE_dupl_symbol(__temp, __last);
+    __first = __temp;
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
                                                     _ForwardIterator __last)
 {
@@ -1499,12 +1711,12 @@
         __temp = __parse_Back_open_paren(__first, __last);
         if (__temp != __first)
         {
+            ++__marked_count_;
             __first = __parse_RE_expression(__temp, __last);
             __temp = __parse_Back_close_paren(__first, __last);
             if (__temp == __first)
                 throw regex_error(regex_constants::error_paren);
             __first = __temp;
-            ++__marked_count_;
         }
         else
             __first = __parse_BACKREF(__first, __last);
@@ -1519,22 +1731,48 @@
                                                        _ForwardIterator __first,
                                                        _ForwardIterator __last)
 {
-    _ForwardIterator __temp = __first;
-    __first = __parse_ORD_CHAR(__first, __last);
+    _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
     if (__temp == __first)
     {
-        __first = __parse_QUOTED_CHAR(__first, __last);
+        __temp = __parse_QUOTED_CHAR(__first, __last);
         if (__temp == __first)
         {
-            if (__first != __last && *__first == '.')
+            if (__temp != __last && *__temp == '.')
             {
                 __push_match_any();
-                ++__first;
+                ++__temp;
             }
             else
-                __first = __parse_bracket_expression(__first, __last);
+                __temp = __parse_bracket_expression(__first, __last);
         }
     }
+    __first = __temp;
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
+                                                       _ForwardIterator __first,
+                                                       _ForwardIterator __last)
+{
+    _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
+    if (__temp == __first)
+    {
+        __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
+        if (__temp == __first)
+        {
+            if (__temp != __last && *__temp == '.')
+            {
+                __push_match_any();
+                ++__temp;
+            }
+            else
+                __temp = __parse_bracket_expression(__first, __last);
+        }
+    }
+    __first = __temp;
     return __first;
 }
 
@@ -1654,6 +1892,44 @@
 template <class _CharT, class _Traits>
 template <class _ForwardIterator>
 _ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
+                                                   _ForwardIterator __last)
+{
+    if (__first != __last)
+    {
+        switch (*__first)
+        {
+        case '^':
+        case '.':
+        case '[':
+        case '$':
+        case '(':
+        case '|':
+        case '*':
+        case '+':
+        case '?':
+        case '{':
+        case '\\':
+            break;
+        case ')':
+            if (__open_count_ == 0)
+            {
+                __push_char(*__first);
+                ++__first;
+            }
+            break;
+        default:
+            __push_char(*__first);
+            ++__first;
+            break;
+        }
+    }
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
                                                   _ForwardIterator __last)
 {
@@ -1685,6 +1961,43 @@
 template <class _CharT, class _Traits>
 template <class _ForwardIterator>
 _ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
+                                                      _ForwardIterator __last)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __temp = next(__first);
+        if (__temp != __last)
+        {
+            if (*__first == '\\')
+            {
+                switch (*__temp)
+                {
+                case '^':
+                case '.':
+                case '*':
+                case '[':
+                case '$':
+                case '\\':
+                case '(':
+                case ')':
+                case '|':
+                case '+':
+                case '?':
+                case '{':
+                    __push_char(*__temp);
+                    __first = ++__temp;
+                    break;
+                }
+            }
+        }
+    }
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
                                                      _ForwardIterator __last)
 {
@@ -1743,6 +2056,75 @@
 template <class _CharT, class _Traits>
 template <class _ForwardIterator>
 _ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
+                                                      _ForwardIterator __last)
+{
+    if (__first != __last)
+    {
+        switch (*__first)
+        {
+        case '*':
+            __push_greedy_inf_repeat(0);
+            ++__first;
+            break;
+        case '+':
+            __push_greedy_inf_repeat(1);
+            ++__first;
+            break;
+        case '?':
+            __push_repeat(0, 1);
+            ++__first;
+            break;
+        case '{':
+            {
+                int __min;
+                _ForwardIterator __temp = __parse_DUP_COUNT(__first, __last, __min);
+                if (__temp == __first)
+                    throw regex_error(regex_constants::error_badbrace);
+                __first = __temp;
+                if (__first == __last)
+                    throw regex_error(regex_constants::error_brace);
+                switch (*__first)
+                {
+                case '}':
+                    __push_exact_repeat(__min);
+                    ++__first;
+                    break;
+                case ',':
+                    if (++__first == __last)
+                        throw regex_error(regex_constants::error_badbrace);
+                    if (*__first == '}')
+                    {
+                        __push_greedy_inf_repeat(__min);
+                        ++__first;
+                    }
+                    else
+                    {
+                        int __max;
+                        __temp = __parse_DUP_COUNT(__first, __last, __max);
+                        if (__temp == __first)
+                            throw regex_error(regex_constants::error_brace);
+                        __first = __temp;
+                        if (__first == __last || *__first != '}')
+                            throw regex_error(regex_constants::error_brace);
+                        ++__first;
+                        if (__max < __min)
+                            throw regex_error(regex_constants::error_badbrace);
+                        __push_repeat(__min, __max);
+                    }
+                default:
+                    throw regex_error(regex_constants::error_badbrace);
+                }
+            }
+            break;
+        }
+    }
+    return __first;
+}
+
+template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
                                                          _ForwardIterator __last)
 {
@@ -1951,9 +2333,442 @@
     return __first;
 }
 
+template <class _CharT, class _Traits>
+void
+basic_regex<_CharT, _Traits>::__push_char(value_type __c)
+{
+    unique_ptr<__state<_CharT> > __new_end(new __state<_CharT>);
+    unique_ptr<__transition<_CharT> > __new_transition(
+        new __match_char<_CharT>(__c, true, __new_end.get()));
+    __state<_CharT>* __e = __new_end.release();
+    if (__end_ == nullptr)
+    {
+        __start_.reset(new __state<_CharT>);
+        __end_ = __start_.get();
+    }
+    __end_->__add_one(__new_transition.release());
+    __end_ = __e;
+}
+
 typedef basic_regex<char>    regex;
 typedef basic_regex<wchar_t> wregex;
 
+// sub_match
+
+template <class _BidirectionalIterator>
+class sub_match
+    : public pair<_BidirectionalIterator, _BidirectionalIterator>
+{
+public:
+    typedef _BidirectionalIterator                              iterator;
+    typedef typename iterator_traits<iterator>::value_type      value_type;
+    typedef typename iterator_traits<iterator>::difference_type difference_type;
+    typedef basic_string<value_type>                            string_type;
+
+    bool matched;
+
+    difference_type length() const
+        {return matched ? _STD::distance(this->first, this->second) : 0;}
+    string_type str() const
+        {return matched ? string_type(this->first, this->second) : string_type();}
+    operator string_type() const
+        {return str();}
+
+    int compare(const sub_match& __s) const
+        {return str().compare(__s.str());}
+    int compare(const string_type& __s) const
+        {return str().compare(__s);}
+    int compare(const value_type* __s) const
+        {return str().compare(__s);}
+};
+
+typedef sub_match<const char*>             csub_match;
+typedef sub_match<const wchar_t*>          wcsub_match;
+typedef sub_match<string::const_iterator>  ssub_match;
+typedef sub_match<wstring::const_iterator> wssub_match;
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return __x.compare(__y) == 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return __x.compare(__y) < 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return __y.compare(__x.c_str()) == 0;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+          const sub_match<_BiIter>& __y)
+{
+    return __y.compare(__x.c_str()) > 0;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+          const sub_match<_BiIter>& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+                const sub_match<_BiIter>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const sub_match<_BiIter>& __x,
+           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return __x.compare(__y.c_str()) == 0;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const sub_match<_BiIter>& __x,
+           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const sub_match<_BiIter>& __x,
+          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return __x.compare(__y.c_str()) < 0;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator>(const sub_match<_BiIter>& __x,
+               const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const sub_match<_BiIter>& __x,
+           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter, class _ST, class _SA>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const sub_match<_BiIter>& __x,
+           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(typename iterator_traits<_BiIter>::value_type const* __x,
+           const sub_match<_BiIter>& __y)
+{
+    return __y.compare(__x) == 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(typename iterator_traits<_BiIter>::value_type const* __x,
+          const sub_match<_BiIter>& __y)
+{
+    return __y.compare(__x) > 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(typename iterator_traits<_BiIter>::value_type const* __x,
+          const sub_match<_BiIter>& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return __x.compare(__y) == 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const sub_match<_BiIter>& __x,
+          typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return __x.compare(__y) < 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const sub_match<_BiIter>& __x,
+          typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const* __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(typename iterator_traits<_BiIter>::value_type const& __x,
+           const sub_match<_BiIter>& __y)
+{
+    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
+    return __y.compare(string_type(1, __x)) == 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(typename iterator_traits<_BiIter>::value_type const& __x,
+          const sub_match<_BiIter>& __y)
+{
+    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
+    return __y.compare(string_type(1, __x)) > 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(typename iterator_traits<_BiIter>::value_type const& __x,
+          const sub_match<_BiIter>& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
+           const sub_match<_BiIter>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
+    return __x.compare(string_type(1, __y)) == 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const sub_match<_BiIter>& __x,
+          typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
+    return __x.compare(string_type(1, __y)) < 0;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const sub_match<_BiIter>& __x,
+          typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    return __y < __x;
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const sub_match<_BiIter>& __x,
+           typename iterator_traits<_BiIter>::value_type const& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _CharT, class _ST, class _BiIter>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _ST>&
+operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
+{
+    return __os << __m.str();
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_REGEX

Modified: libcxx/trunk/test/re/re.regex/re.regex.construct/ptr_flg.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.regex/re.regex.construct/ptr_flg.pass.cpp?rev=107187&r1=107186&r2=107187&view=diff
==============================================================================
--- libcxx/trunk/test/re/re.regex/re.regex.construct/ptr_flg.pass.cpp (original)
+++ libcxx/trunk/test/re/re.regex/re.regex.construct/ptr_flg.pass.cpp Tue Jun 29 13:37:43 2010
@@ -13,6 +13,8 @@
 
 // basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
 
+#include <iostream>
+
 #include <regex>
 #include <cassert>
 

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// int compare(const string_type& s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        typedef SM::string_type string;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(string()) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(string()) > 0);
+        assert(sm.compare(string("123")) == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        typedef SM::string_type string;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(string()) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(string()) > 0);
+        assert(sm.compare(string(L"123")) == 0);
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// int compare(const sub_match& s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(sm2) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(sm2) > 0);
+        sm2.first = s;
+        sm2.second = s + 3;
+        sm2.matched = true;
+        assert(sm.compare(sm2) == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(sm2) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(sm2) > 0);
+        sm2.first = s;
+        sm2.second = s + 3;
+        sm2.matched = true;
+        assert(sm.compare(sm2) == 0);
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// int compare(const value_type* s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare("") == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare("") > 0);
+        assert(sm.compare("123") == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(L"") == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(L"") > 0);
+        assert(sm.compare(L"123") == 0);
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/length.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/length.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/length.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/length.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// difference_type length() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        assert(sm.length() == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.length() == 3);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        assert(sm.length() == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.length() == 3);
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/operator_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/operator_string.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/operator_string.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/operator_string.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// operator string_type() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm;
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm;
+        assert(str == std::string("123"));
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm;
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm;
+        assert(str == std::wstring(L"123"));
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/str.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/str.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/str.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/str.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// string_type str() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm.str();
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm.str();
+        assert(str == std::string("123"));
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm.str();
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm.str();
+        assert(str == std::wstring(L"123"));
+    }
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.op/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.op/compare.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.op/compare.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.op/compare.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,283 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                     const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool operator>(const sub_match<BiIter>& lhs,
+//                    const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator==(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<(typename iterator_traits<BiIter>::value_type const* lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>(typename iterator_traits<BiIter>::value_type const* lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator==(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<(typename iterator_traits<BiIter>::value_type const& lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>(typename iterator_traits<BiIter>::value_type const& lhs,
+//               const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+// 
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test(const std::basic_string<CharT>& x, const std::basic_string<CharT>& y)
+{
+    typedef std::basic_string<CharT> string;
+    typedef std::sub_match<typename string::const_iterator> sub_match;
+    sub_match sm1;
+    sm1.first = x.begin();
+    sm1.second = x.end();
+    sm1.matched = true;
+    sub_match sm2;
+    sm2.first = y.begin();
+    sm2.second = y.end();
+    sm2.matched = true;
+    assert((sm1 == sm2) == (x == y));
+    assert((sm1 != sm2) == (x != y));
+    assert((sm1 < sm2) == (x < y));
+    assert((sm1 > sm2) == (x > y));
+    assert((sm1 <= sm2) == (x <= y));
+    assert((sm1 >= sm2) == (x >= y));
+    assert((x == sm2) == (x == y));
+    assert((x != sm2) == (x != y));
+    assert((x < sm2) == (x < y));
+    assert((x > sm2) == (x > y));
+    assert((x <= sm2) == (x <= y));
+    assert((x >= sm2) == (x >= y));
+    assert((sm1 == y) == (x == y));
+    assert((sm1 != y) == (x != y));
+    assert((sm1 < y) == (x < y));
+    assert((sm1 > y) == (x > y));
+    assert((sm1 <= y) == (x <= y));
+    assert((sm1 >= y) == (x >= y));
+    assert((x.c_str() == sm2) == (x == y));
+    assert((x.c_str() != sm2) == (x != y));
+    assert((x.c_str() < sm2) == (x < y));
+    assert((x.c_str() > sm2) == (x > y));
+    assert((x.c_str() <= sm2) == (x <= y));
+    assert((x.c_str() >= sm2) == (x >= y));
+    assert((sm1 == y.c_str()) == (x == y));
+    assert((sm1 != y.c_str()) == (x != y));
+    assert((sm1 < y.c_str()) == (x < y));
+    assert((sm1 > y.c_str()) == (x > y));
+    assert((sm1 <= y.c_str()) == (x <= y));
+    assert((sm1 >= y.c_str()) == (x >= y));
+    assert((x[0] == sm2) == (string(1, x[0]) == y));
+    assert((x[0] != sm2) == (string(1, x[0]) != y));
+    assert((x[0] < sm2) == (string(1, x[0]) < y));
+    assert((x[0] > sm2) == (string(1, x[0]) > y));
+    assert((x[0] <= sm2) == (string(1, x[0]) <= y));
+    assert((x[0] >= sm2) == (string(1, x[0]) >= y));
+    assert((sm1 == y[0]) == (x == string(1, y[0])));
+    assert((sm1 != y[0]) == (x != string(1, y[0])));
+    assert((sm1 < y[0]) == (x < string(1, y[0])));
+    assert((sm1 > y[0]) == (x > string(1, y[0])));
+    assert((sm1 <= y[0]) == (x <= string(1, y[0])));
+    assert((sm1 >= y[0]) == (x >= string(1, y[0])));
+}
+
+int main()
+{
+    test(std::string("123"), std::string("123"));
+    test(std::string("1234"), std::string("123"));
+    test(std::wstring(L"123"), std::wstring(L"123"));
+    test(std::wstring(L"1234"), std::wstring(L"123"));
+}

Added: libcxx/trunk/test/re/re.submatch/re.submatch.op/stream.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.op/stream.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.op/stream.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.op/stream.pass.cpp Tue Jun 29 13:37:43 2010
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 sub_match;
+
+// template <class charT, class ST, class BiIter>
+//     basic_ostream<charT, ST>&
+//     operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
+
+#include <regex>
+#include <sstream>
+#include <cassert>
+
+template <class CharT>
+void
+test(const std::basic_string<CharT>& s)
+{
+    typedef std::basic_string<CharT> string;
+    typedef std::sub_match<typename string::const_iterator> SM;
+    typedef std::basic_ostringstream<CharT> ostringstream;
+    SM sm;
+    sm.first = s.begin();
+    sm.second = s.end();
+    sm.matched = true;
+    ostringstream os;
+    os << sm;
+    assert(os.str() == s);
+}
+
+int main()
+{
+    test(std::string("123"));
+    test(std::wstring(L"123"));
+}

Added: libcxx/trunk/test/re/re.submatch/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/types.pass.cpp?rev=107187&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/types.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/types.pass.cpp Tue Jun 29 13:37:43 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>
+
+// template <class BidirectionalIterator>
+// class sub_match
+//     : public pair<BidirectionalIterator, BidirectionalIterator>
+// {
+// public:
+//     typedef BidirectionalIterator                               iterator;
+//     typedef typename iterator_traits<iterator>::value_type      value_type;
+//     typedef typename iterator_traits<iterator>::difference_type difference_type;
+//     typedef basic_string<value_type>                            string_type;
+// 
+//     bool matched;
+//     ...
+// };
+
+#include <regex>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::sub_match<char*> SM;
+        static_assert((std::is_same<SM::iterator, char*>::value), "");
+        static_assert((std::is_same<SM::value_type, char>::value), "");
+        static_assert((std::is_same<SM::difference_type, std::ptrdiff_t>::value), "");
+        static_assert((std::is_same<SM::string_type, std::string>::value), "");
+        static_assert((std::is_convertible<SM*, std::pair<char*, char*>*>::value), "");
+
+        SM sm;
+        sm.first = nullptr;
+        sm.second = nullptr;
+        sm.matched = false;
+    }
+    {
+        typedef std::sub_match<wchar_t*> SM;
+        static_assert((std::is_same<SM::iterator, wchar_t*>::value), "");
+        static_assert((std::is_same<SM::value_type, wchar_t>::value), "");
+        static_assert((std::is_same<SM::difference_type, std::ptrdiff_t>::value), "");
+        static_assert((std::is_same<SM::string_type, std::wstring>::value), "");
+        static_assert((std::is_convertible<SM*, std::pair<wchar_t*, wchar_t*>*>::value), "");
+
+        SM sm;
+        sm.first = nullptr;
+        sm.second = nullptr;
+        sm.matched = false;
+    }
+    {
+        static_assert((std::is_same<std::csub_match, std::sub_match<const char*> >::value), "");
+        static_assert((std::is_same<std::wcsub_match, std::sub_match<const wchar_t*> >::value), "");
+        static_assert((std::is_same<std::ssub_match, std::sub_match<std::string::const_iterator> >::value), "");
+        static_assert((std::is_same<std::wssub_match, std::sub_match<std::wstring::const_iterator> >::value), "");
+    }
+}





More information about the cfe-commits mailing list