OSDN Git Service

* include/tr1_impl/regex (basic_regex::basic_regex): Use range
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1_impl / regex
index bf4c309..80bc394 100644 (file)
@@ -1,6 +1,6 @@
 // class template regex -*- C++ -*-
 
-// Copyright (C) 2007 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -29,6 +29,8 @@
 
 /**
  * @file tr1_impl/regex
+ * @brief The common implementation file for tr1 and std regular expressions.
+ *
  *  This is an internal header file, included by other library headers.
  *  You should not attempt to use it directly.
  */
@@ -40,12 +42,15 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
 /**
  * @addtogroup tr1_regex Regular Expressions
  * A facility for performing regular expression pattern matching.
- * @{
  */
+ //@{
 
 namespace regex_constants
 {
-  // [7.5.1] Bitmask Type syntax_option_type
+  /**
+   * @name 5.1 Regular Expression Syntax Options
+   */
+  //@{
   enum __syntax_option
     {
       _S_icase,
@@ -70,72 +75,103 @@ namespace regex_constants
    *
    * A valid value of type syntax_option_type shall have exactly one of the
    * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
-   * set.
+   * %set.
    */
   typedef unsigned int syntax_option_type;
 
-  /// Specifies that the matching of regular expressions against a character
-  /// sequence shall be performed without regard to case.
+  /** 
+   * Specifies that the matching of regular expressions against a character
+   * sequence shall be performed without regard to case.
+   */
   static const syntax_option_type icase      = 1 << _S_icase;
 
-  /// Specifies that when a regular expression is matched against a character
-  /// container sequence, no sub-expression matches are to be stored in the
-  /// supplied match_results structure.
+  /**
+   * Specifies that when a regular expression is matched against a character
+   * container sequence, no sub-expression matches are to be stored in the
+   * supplied match_results structure.
+   */
   static const syntax_option_type nosubs     = 1 << _S_nosubs;
 
-  /// Specifies that the regular expression engine should pay more attention to
-  /// the speed with which regular expressions are matched, and less to the
-  /// speed with which regular expression objects are constructed. Otherwise
-  /// it has no detectable effect on the program output.
+  /**
+   * Specifies that the regular expression engine should pay more attention to
+   * the speed with which regular expressions are matched, and less to the
+   * speed with which regular expression objects are constructed. Otherwise
+   * it has no detectable effect on the program output.
+   */
   static const syntax_option_type optimize   = 1 << _S_optimize;
 
-  /// Specifies that character ranges of the form [a-b] should be locale
-  /// sensitive.
+  /**
+   * Specifies that character ranges of the form [a-b] should be locale
+   * sensitive.
+   */
   static const syntax_option_type collate    = 1 << _S_collate;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
-  /// Language Specification, Standard Ecma-262, third edition, 1999], as
-  /// modified in tr1 section [7.13].  This grammar is similar to that defined
-  /// in the PERL scripting language but extended with elements found in the
-  /// POSIX regular expression grammar.
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
+   * Language Specification, Standard Ecma-262, third edition, 1999], as
+   * modified in tr1 section [7.13].  This grammar is similar to that defined
+   * in the PERL scripting language but extended with elements found in the
+   * POSIX regular expression grammar.
+   */
   static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
-  /// Portable Operating System Interface (POSIX), Base Definitions and
-  /// Headers, Section 9, Regular Expressions [IEEE, Information Technology --
-  /// Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
+   * Portable Operating System Interface (POSIX), Base Definitions and
+   * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
+   * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
+   */
   static const syntax_option_type basic      = 1 << _S_basic;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
-  /// Portable Operating System Interface (POSIX), Base Definitions and Headers,
-  /// Section 9, Regular Expressions.
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
+   * Portable Operating System Interface (POSIX), Base Definitions and Headers,
+   * Section 9, Regular Expressions.
+   */
   static const syntax_option_type extended   = 1 << _S_extended;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by POSIX utility awk in IEEE Std 1003.1-2001.  This option is
-  /// identical to syntax_option_type extended, except that C-style escape
-  /// sequences are supported.  These sequences are, explicitly, '\\', '\a',
-  /// '\b', '\f', '\n', '\r', '\t' , '\v', '\"', '\\', and '\ddd' (where ddd is
-  /// one, two, or three octal digits).  
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by POSIX utility awk in IEEE Std 1003.1-2001.  This option is
+   * identical to syntax_option_type extended, except that C-style escape
+   * sequences are supported.  These sequences are, explicitly, "\\", "\a",
+   * "\b", "\f", "\n", "\r", "\t" , "\v", "\"", "'",
+   * and "\ddd" (where ddd is one, two, or three octal digits).  
+   */
   static const syntax_option_type awk        = 1 << _S_awk;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by POSIX utility grep in IEEE Std 1003.1-2001.  This option is
-  /// identical to syntax_option_type basic, except that newlines are treated
-  /// as whitespace.
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by POSIX utility grep in IEEE Std 1003.1-2001.  This option is
+   * identical to syntax_option_type basic, except that newlines are treated
+   * as whitespace.
+   */
   static const syntax_option_type grep       = 1 << _S_grep;
 
-  /// Specifies that the grammar recognized by the regular expression engine is
-  /// that used by POSIX utility grep when given the -E option in
-  /// IEEE Std 1003.1-2001.  This option is identical to syntax_option_type 
-  /// extended, except that newlines are treated as whitespace.
+  /**
+   * Specifies that the grammar recognized by the regular expression engine is
+   * that used by POSIX utility grep when given the -E option in
+   * IEEE Std 1003.1-2001.  This option is identical to syntax_option_type 
+   * extended, except that newlines are treated as whitespace.
+   */
   static const syntax_option_type egrep      = 1 << _S_egrep;
 
+  //@}
+
+  /**
+   * @name 5.2 Matching Rules
+   *
+   * Matching a regular expression against a sequence of characters [first,
+   * last) proceeds according to the rules of the grammar specified for the
+   * regular expression object, modified according to the effects listed
+   * below for any bitmask elements set.
+   *
+   */
+  //@{
 
-  // [7.5.2] Bitmask Type match_flag_type
   enum __match_flag
     {
       _S_not_bol,
@@ -155,93 +191,122 @@ namespace regex_constants
   /**
    * @brief This is a bitmask type indicating regex matching rules.
    *
-   * Matching a regular expression against a sequence of characters [first,
-   * last) proceeds according to the rules of the grammar specified for the
-   * regular expression object, modified according to the effects listed
-   * below for any bitmask elements set.
-   *
    * The @c match_flag_type is implementation defined but it is valid to
    * perform bitwise operations on these values and expect the right thing to
    * happen.
    */
   typedef std::bitset<_S_match_flag_last> match_flag_type;
 
+  /**
+   * The default matching rules.
+   */
   static const match_flag_type match_default     = 0;
 
-  /// The first character in the sequence [first, last) is treated as though it
-  /// is not at the beginning of a line, so the character "^" in the regular
-  /// expression shall not match [first, first).
+  /**
+   * The first character in the sequence [first, last) is treated as though it
+   * is not at the beginning of a line, so the character "^" in the regular
+   * expression shall not match [first, first).
+   */
   static const match_flag_type match_not_bol     = 1 << _S_not_bol;
 
-  /// The last character in the sequence [first, last) is treated as though it
-  /// is not at the end of a line, so the character "$" in the regular
-  /// expression shall not match [last, last).
+  /**
+   * The last character in the sequence [first, last) is treated as though it
+   * is not at the end of a line, so the character "$" in the regular
+   * expression shall not match [last, last).
+   */
   static const match_flag_type match_not_eol     = 1 << _S_not_eol;
    
-  /// The expression "\b" is not matched against the sub-sequence
-  /// [first,first).
+  /**
+   * The expression "\b" is not matched against the sub-sequence
+   * [first,first).
+   */
   static const match_flag_type match_not_bow     = 1 << _S_not_bow;
    
-  /// The expression "\b" should not be matched against the sub-sequence
-  /// [last,last).
+  /**
+   * The expression "\b" should not be matched against the sub-sequence
+   * [last,last).
+   */
   static const match_flag_type match_not_eow     = 1 << _S_not_eow;
    
-  /// If more than one match is possible then any match is an acceptable
-  /// result.
+  /**
+   * If more than one match is possible then any match is an acceptable
+   * result.
+   */
   static const match_flag_type match_any         = 1 << _S_any;
    
-  /// The expression does not match an empty sequence.
+  /**
+   * The expression does not match an empty sequence.
+   */
   static const match_flag_type match_not_null    = 1 << _S_not_null;
    
-  /// The expression only matches a sub-sequence that begins at first .
+  /**
+   * The expression only matches a sub-sequence that begins at first .
+   */
   static const match_flag_type match_continuous  = 1 << _S_continuous;
    
-  /// --first is a valid iterator position.  When this flag is set then the
-  /// flags match_not_bol and match_not_bow are ignored by the regular
-  /// expression algorithms 7.11 and iterators 7.12.
+  /**
+   * --first is a valid iterator position.  When this flag is set then the
+   * flags match_not_bol and match_not_bow are ignored by the regular
+   * expression algorithms 7.11 and iterators 7.12.
+   */
   static const match_flag_type match_prev_avail  = 1 << _S_prev_avail;
 
-  /// When a regular expression match is to be replaced by a new string, the
-  /// new string is constructed using the rules used by the ECMAScript replace
-  /// function in ECMA- 262 [Ecma International, ECMAScript Language
-  /// Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
-  /// String.prototype.replace. In addition, during search and replace
-  /// operations all non-overlapping occurrences of the regular expression
-  /// are located and replaced, and sections of the input that did not match
-  /// the expression are copied unchanged to the output string.
-  ///
-  /// Format strings (from ECMA-262 [15.5.4.11]):
-  /// $$  $
-  /// $&  The matched substring.
-  /// $`  The portion of <em>string</em> that precedes the matched substring.
-  /// $'  The portion of <em>string</em> that follows the matched substring.
-  /// $n  The nth capture, where n is in [1,9] and $n is not followed by a
-  ///     decimal digit.  If n <= m and the nth capture is undefined, use the
-  ///     empty string
-  ///     instead. If n > m, the result is implementation-defined.
-  /// $nn The nnth capture, where nn is a two-digit decimal number on [01, 99].
-  ///     If nn <= m and the nth capture is undefined, use the empty string
-  ///     instead. If nn > m, the result is implementation-defined.
-  ///
+  /**
+   * When a regular expression match is to be replaced by a new string, the
+   * new string is constructed using the rules used by the ECMAScript replace
+   * function in ECMA- 262 [Ecma International, ECMAScript Language
+   * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
+   * String.prototype.replace. In addition, during search and replace
+   * operations all non-overlapping occurrences of the regular expression
+   * are located and replaced, and sections of the input that did not match
+   * the expression are copied unchanged to the output string.
+   * 
+   * Format strings (from ECMA-262 [15.5.4.11]):
+   * @li $$  The dollar-sign itself ($)
+   * @li $&  The matched substring.
+   * @li $`  The portion of <em>string</em> that precedes the matched substring.
+   *         This would be match_results::prefix().
+   * @li $'  The portion of <em>string</em> that follows the matched substring.
+   *         This would be match_results::suffix().
+   * @li $n  The nth capture, where n is in [1,9] and $n is not followed by a
+   *         decimal digit.  If n <= match_results::size() and the nth capture
+   *         is undefined, use the empty string instead.  If n >
+   *         match_results::size(), the result is implementation-defined.
+   * @li $nn The nnth capture, where nn is a two-digit decimal number on
+   *         [01, 99].  If nn <= match_results::size() and the nth capture is
+   *         undefined, use the empty string instead. If
+   *         nn > match_results::size(), the result is implementation-defined.
+   */
   static const match_flag_type format_default    = 0;
 
-  /// When a regular expression match is to be replaced by a new string, the
-  /// new string is constructed using the rules used by the POSIX sed utility
-  /// in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
-  /// Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
+  /**
+   * When a regular expression match is to be replaced by a new string, the
+   * new string is constructed using the rules used by the POSIX sed utility
+   * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
+   * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
+   */
   static const match_flag_type format_sed        = 1 << _S_sed;
 
-  /// During a search and replace operation, sections of the character
-  /// container sequence being searched that do not match the regular
-  /// expression shall not be copied to the output string.
+  /**
+   * During a search and replace operation, sections of the character
+   * container sequence being searched that do not match the regular
+   * expression shall not be copied to the output string.
+   */
   static const match_flag_type format_no_copy    = 1 << _S_no_copy;
 
-  /// When specified during a search and replace operation, only the first
-  /// occurrence of the regular expression shall be replaced.
+  /**
+   * When specified during a search and replace operation, only the first
+   * occurrence of the regular expression shall be replaced.
+   */
   static const match_flag_type format_first_only = 1 << _S_first_only;
 
+  //@}
 
-  // [7.5.3] implementation-defined error type
+  /**
+   * @name 5.3 Error Types
+   */
+  //@{
   enum error_type
     {
       _S_error_collate,
@@ -260,63 +325,78 @@ namespace regex_constants
       _S_error_last
     };
 
-  /// The expression contained an invalid collating element name.
+  /** The expression contained an invalid collating element name. */
   static const error_type error_collate(_S_error_collate);
 
-  /// The expression contained an invalid character class name.
+  /** The expression contained an invalid character class name. */
   static const error_type error_ctype(_S_error_ctype);
 
-  /// The expression contained an invalid escaped character, or a trailing
-  /// escape.
+  /**
+   * The expression contained an invalid escaped character, or a trailing
+   * escape.
+   */
   static const error_type error_escape(_S_error_escape);
 
-  /// The expression contained an invalid back reference.
+  /** The expression contained an invalid back reference. */
   static const error_type error_backref(_S_error_backref);
 
-  /// The expression contained mismatched [ and ].
+  /** The expression contained mismatched [ and ]. */
   static const error_type error_brack(_S_error_brack);
 
-  /// The expression contained mismatched ( and ).
+  /** The expression contained mismatched ( and ). */
   static const error_type error_paren(_S_error_paren);
 
-  /// The expression contained mismatched { and }
+  /** The expression contained mismatched { and } */
   static const error_type error_brace(_S_error_brace);
 
-  /// The expression contained an invalid range in a {} expression.
+  /** The expression contained an invalid range in a {} expression. */
   static const error_type error_badbrace(_S_error_badbrace);
 
-  /// The expression contained an invalid character range,
-  /// such as [b-a] in most encodings.
+  /**
+   * The expression contained an invalid character range,
+   * such as [b-a] in most encodings.
+   */
   static const error_type error_range(_S_error_range);
 
-  /// There was insufficient memory to convert the expression into a
-  /// finite state machine.
+  /**
+   * There was insufficient memory to convert the expression into a
+   * finite state machine.
+   */
   static const error_type error_space(_S_error_space);
 
-  /// One of *?+{ was not preceded by a valid regular expression.
+  /**
+   * One of "*?+{" was not preceded by a valid regular expression.
+   */
   static const error_type error_badrepeat(_S_error_badrepeat);
 
-  /// The complexity of an attempted match against a regular expression
-  /// exceeded a pre-set level.
+  /**
+   * The complexity of an attempted match against a regular expression
+   * exceeded a pre-set level.
+   */
   static const error_type error_complexity(_S_error_complexity);
 
-  /// There was insufficient memory to determine whether the
-  /// regular expression could match the specified character sequence.
+  /**
+   * There was insufficient memory to determine whether the
+   * regular expression could match the specified character sequence.
+   */
   static const error_type error_stack(_S_error_stack);
+
+  //@}
 }
 
 
   // [7.8] Class regex_error
   /**
-   * Defines the type of objects thrown as exceptions to report errors from the
-   * regular expression library.
+   * @brief A regular expression exception class.
+   *
+   * The regular expression library throws objects of this class on error.
    */
   class regex_error
   : public std::runtime_error
   {
   public:
     /**
-     * @brief constructs a regex_error object.
+     * @brief Constructs a regex_error object.
      *
      * @param ecode the regex error code.
      */
@@ -326,7 +406,7 @@ namespace regex_constants
     { }
 
     /**
-     * @brief gets the regex error code.
+     * @brief Gets the regex error code.
      *
      * @returns the regex error code.
      */
@@ -338,9 +418,10 @@ namespace regex_constants
     regex_constants::error_type _M_code;
   };
 
-
   // [7.7] Class regex_traits
   /**
+   * @brief Describes aspects of a regular expression.
+   *
    * A regular expression traits class that satisfies the requirements of tr1
    * section [7.2].
    *
@@ -454,8 +535,7 @@ namespace regex_constants
        */
       template<typename _Fwd_iter>
         string_type
-        transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
-        { return string_type(); }
+        transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
 
       /**
        * @brief Gets a collation element by name.
@@ -472,11 +552,10 @@ namespace regex_constants
        */
       template<typename _Fwd_iter>
         string_type
-        lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
-        { return string_type(); }
+        lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
 
       /**
-       * @brief Maps one or mire characters to a named character
+       * @brief Maps one or more characters to a named character
        *        classification.
        *
        * @param first beginning of the character sequence.
@@ -510,8 +589,7 @@ namespace regex_constants
        */
       template<typename _Fwd_iter>
         char_class_type
-        lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const
-        { return 0; }
+        lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
 
       /**
        * @brief Determines if @p c is a member of an identified class.
@@ -526,38 +604,7 @@ namespace regex_constants
        *         facet.
        */
       bool
-      isctype(_Ch_type __c, char_class_type __f) const
-      {
-       using std::ctype;
-       using std::use_facet;
-       const ctype<_Ch_type>& __ctype(use_facet<
-                                      ctype<_Ch_type> >(_M_locale));
-       
-       if (__ctype.is(__c, __f))
-         return true;
-       
-       // special case of underscore in [[:w:]]
-       if (__c == __ctype.widen('_'))
-         {
-           const char* const __wb[] = "w";
-           char_class_type __wt = this->lookup_classname(__wb,
-                                                         __wb + sizeof(__wb));
-           if (__f | __wt)
-             return true;
-         }
-      
-       // special case of [[:space:]] in [[:blank:]]
-       if (__c == __ctype.isspace(__c))
-         {
-           const char* const __bb[] = "blank";
-           char_class_type __bt = this->lookup_classname(__bb,
-                                                         __bb + sizeof(__bb));
-           if (__f | __bt)
-             return true;
-         }
-       
-       return false;
-      }
+      isctype(_Ch_type __c, char_class_type __f) const;
 
       /**
        * @brief Converts a digit to an int.
@@ -568,8 +615,6 @@ namespace regex_constants
        * 
        * @returns the value represented by the digit ch in base radix if the
        * character ch is a valid digit in base radix; otherwise returns -1.
-       *
-       * @todo Implement this function.
        */
       int
       value(_Ch_type __ch, int __radix) const;
@@ -604,6 +649,54 @@ namespace regex_constants
       locale_type _M_locale;
     };
 
+  template<typename _Ch_type>
+    bool regex_traits<_Ch_type>::
+    isctype(_Ch_type __c, char_class_type __f) const
+    {
+      using std::ctype;
+      using std::use_facet;
+      const ctype<_Ch_type>& __ctype(use_facet<
+                                    ctype<_Ch_type> >(_M_locale));
+      
+      if (__ctype.is(__c, __f))
+       return true;
+      
+      // special case of underscore in [[:w:]]
+      if (__c == __ctype.widen('_'))
+       {
+         const char* const __wb[] = "w";
+         char_class_type __wt = this->lookup_classname(__wb,
+                                                       __wb + sizeof(__wb));
+         if (__f | __wt)
+           return true;
+       }
+    
+      // special case of [[:space:]] in [[:blank:]]
+      if (__c == __ctype.isspace(__c))
+       {
+         const char* const __bb[] = "blank";
+         char_class_type __bt = this->lookup_classname(__bb,
+                                                       __bb + sizeof(__bb));
+         if (__f | __bt)
+           return true;
+       }
+      
+      return false;
+    }
+
+  template<typename _Ch_type>
+    int regex_traits<_Ch_type>::
+    value(_Ch_type __ch, int __radix) const
+    {
+      std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
+      int __v = -1;
+      if (__radix == 8)
+       __is >> std::oct;
+      else if (__radix == 16)
+       __is >> std::hex;
+      __is >> __v;
+      return __v;
+    }
 
   // [7.8] Class basic_regex
   /**
@@ -623,7 +716,11 @@ namespace regex_constants
       typedef typename _Rx_traits::locale_type  locale_type;
       typedef typename _Rx_traits::string_type  string_type;
 
-      // [7.8.1] constants
+      /**
+       * @name Constants
+       * tr1 [7.8.1] std [28.8.1]
+       */
+      //@{
       static const regex_constants::syntax_option_type icase
         = regex_constants::icase;
       static const regex_constants::syntax_option_type nosubs
@@ -644,6 +741,7 @@ namespace regex_constants
         = regex_constants::grep;
       static const regex_constants::syntax_option_type egrep
         = regex_constants::egrep;
+      //@}
 
       // [7.8.2] construct/copy/destroy
       /**
@@ -698,18 +796,18 @@ namespace regex_constants
 
       /**
        * @brief Constructs a basic regular expression from the string
-       * @p interpreted according to the flags in @p f.
+       * @p interpreted according to the flags in @p f.
        *
-       * @param p A string containing a regular expression.
+       * @param s A string containing a regular expression.
        * @param f Flags indicating the syntax rules and options.
        *
-       * @throws regex_error if @p p is not a valid regular expression.
+       * @throws regex_error if @p s is not a valid regular expression.
        */
       template<typename _Ch_traits, typename _Ch_alloc>
         explicit
         basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
                    flag_type __f = regex_constants::ECMAScript)
-       : _M_flags(__f), _M_pattern(__s), _M_mark_count(0)
+       : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
         { _M_compile(); }
 
       /**
@@ -722,7 +820,8 @@ namespace regex_constants
        *              expression.
        * @param f     The format flags of the regular expression.
        *
-       * @throws regex_error if @p p is not a valid regular expression.
+       * @throws regex_error if @p [first, last) is not a valid regular
+       *         expression.
        */
       template<typename _InputIterator>
         basic_regex(_InputIterator __first, _InputIterator __last, 
@@ -730,6 +829,21 @@ namespace regex_constants
        : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
         { _M_compile(); }
 
+#ifdef _GLIBCXX_INCLUDE_AS_CXX0X
+      /**
+       * @brief Constructs a basic regular expression from an initializer list.
+       *
+       * @param l  The initializer list.
+       * @param f  The format flags of the regular expression.
+       *
+       * @throws regex_error if @p l is not a valid regular expression.
+       */
+      basic_regex(initializer_list<_Ch_type> __l,
+                 flag_type __f = regex_constants::ECMAScript)
+       : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
+        { _M_compile(); }
+#endif
+
       /**
        * @brief Destroys a basic regular expression.
        */
@@ -846,7 +960,7 @@ namespace regex_constants
        *
        * @throws regex_error if p does not contain a valid regular expression
        * pattern interpreted according to @p flags.  If regex_error is thrown,
-       * *this remains unchanged.
+       * the object remains unchanged.
        */
       template<typename _InputIterator>
         basic_regex&
@@ -854,6 +968,23 @@ namespace regex_constants
               flag_type __flags = regex_constants::ECMAScript)
         { return this->assign(string_type(__first, __last), __flags); }
 
+#ifdef _GLIBCXX_INCLUDE_AS_CXX0X
+      /**
+       * @brief Assigns a new regular expression to a regex object.
+       *
+       * @param l     An initializer list representing a regular expression.
+       * @param flags Syntax option flags.
+       *
+       * @throws regex_error if @p l does not contain a valid regular
+       * expression pattern interpreted according to @p flags.  If regex_error
+       * is thrown, the object remains unchanged.
+       */
+      basic_regex&
+      assign(initializer_list<_Ch_type> __l,
+            flag_type __f = regex_constants::ECMAScript)
+      { return this->assign(__l.begin(), __l.end(), __f); }
+#endif
+
       // [7.8.4] const operations
       /**
        * @brief Gets the number of marked subexpressions within the regular
@@ -909,8 +1040,7 @@ namespace regex_constants
        * @brief Compiles a regular expression pattern into a NFA.
        * @todo Implement this function.
        */
-      void _M_compile()
-      { }
+      void _M_compile();
 
     protected:
       flag_type    _M_flags;
@@ -919,8 +1049,10 @@ namespace regex_constants
       _Rx_traits   _M_traits;
     };
   
+  /** @brief Standard regular expressions. */
   typedef basic_regex<char>    regex;
 #ifdef _GLIBCXX_USE_WCHAR_T
+  /** @brief Standard wide-character regular expressions. */
   typedef basic_regex<wchar_t> wregex;
 #endif
 
@@ -935,7 +1067,7 @@ namespace regex_constants
     inline void
     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
         basic_regex<_Ch_type, _Rx_traits>& __rhs)
-    { return __lhs.swap(__rhs); }
+    { __lhs.swap(__rhs); }
 
 
   // [7.9] Class template sub_match
@@ -1041,10 +1173,14 @@ namespace regex_constants
     };
   
   
+  /** @brief Standard regex submatch over a C-style null-terminated string. */
   typedef sub_match<const char*>             csub_match;
+  /** @brief Standard regex submatch over a standard string. */
   typedef sub_match<string::const_iterator>  ssub_match;
 #ifdef _GLIBCXX_USE_WCHAR_T
+  /** @brief Regex submatch over a C-style null-terminated wide string. */
   typedef sub_match<const wchar_t*>          wcsub_match;
+  /** @brief Regex submatch over a standard wide string. */
   typedef sub_match<wstring::const_iterator> wssub_match;
 #endif
 
@@ -1602,6 +1738,8 @@ namespace regex_constants
 
   // [7.10] Class template match_results
   /**
+   * @brief The results of a match or search operation.
+   *
    * A collection of character sequences representing the result of a regular
    * expression match.  Storage for the collection is allocated and freed as
    * necessary by the member functions of class template match_results.
@@ -1618,6 +1756,8 @@ namespace regex_constants
    * of characters [first, second) which formed that match. Otherwise matched
    * is false, and members first and second point to the end of the sequence
    * that was searched.
+   *
+   * @nosubgrouping
    */
   template<typename _Bi_iter,
           typename _Allocator = allocator<sub_match<_Bi_iter> > >
@@ -1629,6 +1769,10 @@ namespace regex_constants
                                                               _Base_type;
 
     public:
+      /**
+       * @name 10.? Public Types
+       */
+      //@{
       typedef sub_match<_Bi_iter>                             value_type;
       typedef typename _Allocator::const_reference            const_reference;
       typedef const_reference                                 reference;
@@ -1640,11 +1784,17 @@ namespace regex_constants
       typedef _Allocator                                      allocator_type;
       typedef typename iterator_traits<_Bi_iter>::value_type  char_type;
       typedef basic_string<char_type>                         string_type;
+      //@}
   
     public:
-      // [7.10.1] construct/copy/destroy
       /**
-       * @brief Constructs a default match_results container.
+       * @name 10.1 Construction, Copying, and Destruction
+       */
+      //@{
+
+      /**
+       * @brief Constructs a default %match_results container.
+       * @post size() returns 0 and str() returns an empty string.
        */
       explicit
       match_results(const _Allocator& __a = _Allocator())
@@ -1652,7 +1802,7 @@ namespace regex_constants
       { }
 
       /**
-       * @brief Copy constructs a match_result.
+       * @brief Copy constructs a %match_results.
        */
       match_results(const match_results& __rhs)
       : _Base_type(__rhs), _M_matched(__rhs._M_matched),
@@ -1667,47 +1817,75 @@ namespace regex_constants
       {
        match_results __tmp(__rhs);
        this->swap(__tmp);
+       return *this;
       }
 
       /**
-       * @todo Implement this function.
+       * @brief Destroys a %match_results object.
        */
       ~match_results()
       { }
       
-      // [7.10.2] size
+      //@}
+
       /**
-       * @todo Document this function.
+       * @name 10.2 Size
+       */
+      //@{
+
+      /**
+       * @brief Gets the number of matches and submatches.
+       *
+       * The number of matches for a given regular expression will be either 0
+       * if there was no match or mark_count() + 1 if a match was successful.
+       * Some matches may be empty.
+       *
+       * @returns the number of matches found.
        */
       size_type
       size() const
       { return _M_matched ? _Base_type::size() + 1 : 0; }
       
-      /**
-       * @todo Implement this function.
-       */
       //size_type
       //max_size() const;
       using _Base_type::max_size;
 
       /**
-       * @todo Document this function.
+       * @brief Indicates if the %match_results contains no results.
+       * @retval true The %match_results object is empty.
+       * @retval false The %match_results object is not empty.
        */
       bool
       empty() const
       { return size() == 0; }
       
-      // [7.10.3] element access
+      //@}
+
+      /**
+       * @name 10.3 Element Access
+       */
+      //@{
+
       /**
        * @brief Gets the length of the indicated submatch.
        * @param sub indicates the submatch.
+       *
+       * This function returns the length of the indicated submatch, or the
+       * length of the entire match if @p sub is zero (the default).
        */
       difference_type
       length(size_type __sub = 0) const
       { return _M_matched ? this->str(__sub).length() : 0; }
 
       /**
-       * @todo Document this function.
+       * @brief Gets the offset of the beginning of the indicated submatch.
+       * @param sub indicates the submatch.
+       *
+       * This function returns the offset from the beginning of the target
+       * sequence to the beginning of the submatch, unless the value of @p sub
+       * is zero (the default), in which case this function returns the offset
+       * from the beginning of the target sequence to the beginning of the
+       * match.
        */
       difference_type
       position(size_type __sub = 0) const
@@ -1717,48 +1895,96 @@ namespace regex_constants
       }
 
       /**
-       * @todo Document this function.
+       * @brief Gets the match or submatch converted to a string type.
+       * @param sub indicates the submatch.
+       *
+       * This function gets the submatch (or match, if @p sub is zero) extracted
+       * from the target range and converted to the associated string type.
        */
       string_type
       str(size_type __sub = 0) const
       { return _M_matched ? (*this)[__sub].str() : string_type(); }
       
       /**
-       * @todo Document this function.
+       * @brief Gets a %sub_match reference for the match or submatch.
+       * @param sub indicates the submatch.
+       *
+       * This function gets a reference to the indicated submatch, or the entire
+       * match if @p sub is zero.
+       *
+       * If @p sub >= size() then this function returns a %sub_match with a
+       * special value indicating no submatch.
        */
       const_reference
-      operator[](size_type __n) const
-      { return _Base_type::operator[](__n); }
+      operator[](size_type __sub) const
+      { return _Base_type::operator[](__sub); }
 
       /**
-       * @todo Document this function.
+       * @brief Gets a %sub_match representing the match prefix.
+       *
+       * This function gets a reference to a %sub_match object representing the
+       * part of the target range between the start of the target range and the
+       * start of the match.
        */
       const_reference
       prefix() const
       { return _M_prefix; }
 
       /**
-       * @todo Document this function.
+       * @brief Gets a %sub_match representing the match suffix.
+       *
+       * This function gets a reference to a %sub_match object representing the
+       * part of the target range between the end of the match and the end of
+       * the target range.
        */
       const_reference
       suffix() const
       { return _M_suffix; }
 
       /**
-       * @todo Document this function.
+       * @brief Gets an iterator to the start of the %sub_match collection.
        */
       const_iterator
       begin() const
       { return _Base_type::begin(); }
       
+#ifdef _GLIBCXX_INCLUDE_AS_CXX0X
       /**
-       * @todo Document this function.
+       * @brief Gets an iterator to the start of the %sub_match collection.
+       */
+      const_iterator
+      cbegin() const
+      { return _Base_type::begin(); }
+#endif
+
+      /**
+       * @brief Gets an iterator to one-past-the-end of the collection.
        */
       const_iterator
       end() const
       { return _Base_type::end(); }
       
-      // [7.10.4] format
+#ifdef _GLIBCXX_INCLUDE_AS_CXX0X
+      /**
+       * @brief Gets an iterator to one-past-the-end of the collection.
+       */
+      const_iterator
+      cend() const
+      { return _Base_type::end(); }
+#endif
+
+      //@}
+
+      /**
+       * @name 10.4 Formatting
+       *
+       * These functions perform formatted substitution of the matched character
+       * sequences into their target.  The format specifiers and escape sequences
+       * accepted by these functions are determined by their @p flags parameter 
+       * as documented above.
+       */
+       //@{
+
       /**
        * @todo Implement this function.
        */
@@ -1766,8 +1992,7 @@ namespace regex_constants
         _Out_iter
         format(_Out_iter __out, const string_type& __fmt,
               regex_constants::match_flag_type __flags
-              = regex_constants::format_default) const
-        { return __out; }
+              = regex_constants::format_default) const;
 
       /**
        * @todo Implement this function.
@@ -1777,17 +2002,29 @@ namespace regex_constants
             regex_constants::match_flag_type __flags
             = regex_constants::format_default) const;
 
-      // [7.10.5] allocator
+      //@} 
+
       /**
-       * @todo Document this function.
+       * @name 10.5 Allocator
+       */
+      //@{ 
+
+      /**
+       * @brief Gets a copy of the allocator.
        */
       //allocator_type
       //get_allocator() const;
       using _Base_type::get_allocator;
       
-      // [7.10.6] swap
+      //@} 
+
+      /**
+       * @name 10.6 Swap
+       */
+       //@{ 
+
       /**
-       * @todo Document this function.
+       * @brief Swaps the contents of two match_results.
        */
       void
       swap(match_results& __that)
@@ -1797,6 +2034,7 @@ namespace regex_constants
        std::swap(_M_prefix,  __that._M_prefix);
        std::swap(_M_suffix,  __that._M_suffix);
       }
+      //@} 
       
     private:
       bool       _M_matched;
@@ -1813,6 +2051,9 @@ namespace regex_constants
 
   // match_results comparisons
   /**
+   * @brief Compares two match_results for equality.
+   * @returns true if the two objects refer to the same match,
+   * false otherwise.
    * @todo Implement this function.
    */
   template<typename _Bi_iter, typename _Allocator>
@@ -1821,12 +2062,15 @@ namespace regex_constants
               const match_results<_Bi_iter, _Allocator>& __m2);
 
   /**
-   * @todo Implement this function.
+   * @brief Compares two match_results for inequality.
+   * @returns true if the two objects do not refer to the same match,
+   * false otherwise.
    */
   template<typename _Bi_iter, class _Allocator>
     inline bool
     operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
-              const match_results<_Bi_iter, _Allocator>& __m2);
+              const match_results<_Bi_iter, _Allocator>& __m2)
+    { return !(__m1 == __m2); }
 
   // [7.10.6] match_results swap
   /**
@@ -1840,10 +2084,15 @@ namespace regex_constants
     inline void
     swap(match_results<_Bi_iter, _Allocator>& __lhs,
         match_results<_Bi_iter, _Allocator>& __rhs)
-    { return __lhs.swap(__rhs); }
+    { __lhs.swap(__rhs); }
 
   // [7.11.2] Function template regex_match
   /**
+   * @name Matching, Searching, and Replacing
+   */
+  //@{
+
+  /**
    * @brief Determines if there is a match between the regular expression @p e
    * and all of the character sequence [first, last).
    *
@@ -1856,6 +2105,8 @@ namespace regex_constants
    * @retval true  A match exists.
    * @retval false Otherwise.
    *
+   * @throws an exception of type regex_error.
+   *
    * @todo Implement this function.
    */
   template<typename _Bi_iter, typename _Allocator,
@@ -1865,8 +2116,7 @@ namespace regex_constants
                match_results<_Bi_iter, _Allocator>& __m,
                const basic_regex<_Ch_type, _Rx_traits>& __re,
                regex_constants::match_flag_type __flags
-               = regex_constants::match_default)
-    { return false; }
+               = regex_constants::match_default);
 
   /**
    * @brief Indicates if there is a match between the regular expression @p e
@@ -1879,6 +2129,8 @@ namespace regex_constants
    *
    * @retval true  A match exists.
    * @retval false Otherwise.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
     bool
@@ -1902,6 +2154,8 @@ namespace regex_constants
    *
    * @retval true  A match exists.
    * @retval false Otherwise.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
     inline bool
@@ -1923,6 +2177,8 @@ namespace regex_constants
    *
    * @retval true  A match exists.
    * @retval false Otherwise.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_traits, typename _Ch_alloc,
           typename _Allocator, typename _Ch_type, typename _Rx_traits>
@@ -1945,6 +2201,8 @@ namespace regex_constants
    *
    * @retval true  A match exists.
    * @retval false Otherwise.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_type, class _Rx_traits>
     inline bool
@@ -1964,6 +2222,8 @@ namespace regex_constants
    *
    * @retval true  A match exists.
    * @retval false Otherwise.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_traits, typename _Str_allocator,
           typename _Ch_type, typename _Rx_traits>
@@ -1985,6 +2245,9 @@ namespace regex_constants
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string, the content of %m is
    *               undefined.
+   *
+   * @throws an exception of type regex_error.
+   *
    * @todo Implement this function.
    */
   template<typename _Bi_iter, typename _Allocator,
@@ -1994,8 +2257,7 @@ namespace regex_constants
                 match_results<_Bi_iter, _Allocator>& __m,
                 const basic_regex<_Ch_type, _Rx_traits>& __re,
                 regex_constants::match_flag_type __flags
-                = regex_constants::match_default)
-    { return false; }
+                = regex_constants::match_default);
 
   /**
    * Searches for a regular expression within a range.
@@ -2005,7 +2267,9 @@ namespace regex_constants
    * @param flags [IN]  Search policy flags.
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string.
-   * @todo Document me.
+   * @doctodo
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
     inline bool
@@ -2027,7 +2291,9 @@ namespace regex_constants
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string, the content of %m is
    *               undefined.
-   * @todo Document me.
+   * @doctodo
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_type, class _Allocator, class _Rx_traits>
     inline bool
@@ -2045,7 +2311,9 @@ namespace regex_constants
    * @param f [IN]  Search policy flags.
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string.
-   * @todo Document me.
+   * @doctodo
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_type, typename _Rx_traits>
     inline bool
@@ -2062,7 +2330,9 @@ namespace regex_constants
    * @param flags [IN]  Search policy flags.
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string.
-   * @todo Document me.
+   * @doctodo
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_traits, typename _String_allocator,
           typename _Ch_type, typename _Rx_traits>
@@ -2083,6 +2353,8 @@ namespace regex_constants
    * @retval true  A match was found within the string.
    * @retval false No match was found within the string, the content of %m is
    *               undefined.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Ch_traits, typename _Ch_alloc,
           typename _Allocator, typename _Ch_type,
@@ -2096,10 +2368,20 @@ namespace regex_constants
                 = regex_constants::match_default)
     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
 
-  // [7.11.4] Function template regex_replace
+  // tr1 [7.11.4] std [28.11.4] Function template regex_replace
   /**
+   * @doctodo
+   * @param out
+   * @param first
+   * @param last
+   * @param e
+   * @param fmt
+   * @param flags
+   *
+   * @returns out
+   * @throws an exception of type regex_error.
+   *
    * @todo Implement this function.
-   * @todo Document this function.
    */
   template<typename _Out_iter, typename _Bi_iter,
           typename _Rx_traits, typename _Ch_type>
@@ -2108,11 +2390,18 @@ namespace regex_constants
                  const basic_regex<_Ch_type, _Rx_traits>& __e,
                  const basic_string<_Ch_type>& __fmt,
                  regex_constants::match_flag_type __flags
-                 = regex_constants::match_default)
-    { return __out; }
+                 = regex_constants::match_default);
 
   /**
-   * @todo Document me.
+   * @doctodo
+   * @param s
+   * @param e
+   * @param fmt
+   * @param flags
+   *
+   * @returns a copy of string @p s with replacements.
+   *
+   * @throws an exception of type regex_error.
    */
   template<typename _Rx_traits, typename _Ch_type>
     inline basic_string<_Ch_type>
@@ -2128,7 +2417,9 @@ namespace regex_constants
       return __result;
     }
 
-  // [7.12.1] Class template regex_iterator
+  //@}
+
+  // tr1 [7.12.1] std [28.12] Class template regex_iterator
   /**
    * An iterator adaptor that will provide repeated calls of regex_search over 
    * a range until no more matches remain.
@@ -2151,7 +2442,7 @@ namespace regex_constants
        * @brief Provides a singular iterator, useful for indicating
        * one-past-the-end of a range.
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator();
       
@@ -2162,7 +2453,7 @@ namespace regex_constants
        * @param re [IN] The regular expression to match.
        * @param m  [IN] Policy flags for match rules.
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
                     regex_constants::match_flag_type __m
@@ -2171,55 +2462,55 @@ namespace regex_constants
       /**
        * Copy constructs a %regex_iterator.
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator(const regex_iterator& __rhs);
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator&
       operator=(const regex_iterator& __rhs);
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       bool
       operator==(const regex_iterator& __rhs);
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       bool
       operator!=(const regex_iterator& __rhs);
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       const value_type&
       operator*();
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       const value_type*
       operator->();
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator&
       operator++();
       
       /**
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_iterator
       operator++(int);
@@ -2290,7 +2581,7 @@ namespace regex_constants
        * @param m          [IN] Policy flags for match rules.
        *
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
                           int __submatch = 0,
@@ -2307,7 +2598,7 @@ namespace regex_constants
        * @param m          [IN] Policy flags for match rules.
        *
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
                           const regex_type& __re,
@@ -2325,7 +2616,7 @@ namespace regex_constants
        * @param m          [IN] Policy flags for match rules.
        
        * @todo Implement this function.
-       * @todo Document this function.
+       * @doctodo
        */
       template<std::size_t _Nm>
         regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
@@ -2401,14 +2692,18 @@ namespace regex_constants
       std::vector<int>  __subs;
     };
 
+  /** @brief Token iterator for C-style NULL-terminated strings. */
   typedef regex_token_iterator<const char*>             cregex_token_iterator;
+  /** @brief Token iterator for standard strings. */
   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
 #ifdef _GLIBCXX_USE_WCHAR_T
+  /** @brief Token iterator for C-style NULL-terminated wide strings. */
   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
+  /** @brief Token iterator for standard wide-character strings. */
   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
 #endif
   
-  /** @} */ // group tr1_regex
+  //@} // group tr1_regex
   
 _GLIBCXX_END_NAMESPACE_TR1
 }