regex_compiler.h (__detail::__compile_nfa): Overload so that std::basic_string<C...
authorJonathan Wakely <jwakely.gcc@gmail.com>
Fri, 8 Nov 2013 14:30:40 +0000 (14:30 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 8 Nov 2013 14:30:40 +0000 (14:30 +0000)
* include/bits/regex_compiler.h (__detail::__compile_nfa): Overload
so that std::basic_string<C> and std::vector<C> iterators dispatch to
the const C* compiler.

From-SVN: r204574

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/regex_compiler.h

index 93203c2..ea2e6c7 100644 (file)
        _CharT template parameters.
        * include/bits/regex_compiler.tcc: Likewise.
 
+       * include/bits/regex_compiler.h (__detail::__compile_nfa): Overload
+       so that std::basic_string<C> and std::vector<C> iterators dispatch to
+       the const C* compiler.
+
 2013-11-06  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * include/bits/regex_automaton.h (_S_opcode_word_boundry): Rename to
index 406d9a9..741098f 100644 (file)
@@ -129,8 +129,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _StackT         _M_stack;
     };
 
+  template<typename _Tp>
+    struct __has_contiguous_iter : std::false_type { };
+
+  template<typename _Ch, typename _Tr, typename _Alloc>
+    struct __has_contiguous_iter<std::basic_string<_Ch, _Tr, _Alloc>>
+    : std::true_type
+    { };
+
+  template<typename _Tp, typename _Alloc>
+    struct __has_contiguous_iter<std::vector<_Tp, _Alloc>>
+    : std::true_type
+    { };
+
+  template<typename _Tp>
+    struct __is_contiguous_normal_iter : std::false_type { };
+
+  template<typename _Tp, typename _Cont>
+    struct
+    __is_contiguous_normal_iter<__gnu_cxx::__normal_iterator<_Tp, _Cont>>
+    : __has_contiguous_iter<_Cont>::type
+    { };
+
+  template<typename _Iter, typename _TraitsT>
+    using __enable_if_contiguous_normal_iter
+      = typename enable_if< __is_contiguous_normal_iter<_Iter>::value,
+                           std::shared_ptr<_NFA<_TraitsT>> >::type;
+
+  template<typename _Iter, typename _TraitsT>
+    using __disable_if_contiguous_normal_iter
+      = typename enable_if< !__is_contiguous_normal_iter<_Iter>::value,
+                           std::shared_ptr<_NFA<_TraitsT>> >::type;
+
   template<typename _FwdIter, typename _TraitsT>
-    inline std::shared_ptr<_NFA<_TraitsT>>
+    inline __disable_if_contiguous_normal_iter<_FwdIter, _TraitsT>
     __compile_nfa(_FwdIter __first, _FwdIter __last, const _TraitsT& __traits,
                  regex_constants::syntax_option_type __flags)
     {
@@ -138,6 +170,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
     }
 
+  template<typename _Iter, typename _TraitsT>
+    inline __enable_if_contiguous_normal_iter<_Iter, _TraitsT>
+    __compile_nfa(_Iter __first, _Iter __last, const _TraitsT& __traits,
+                 regex_constants::syntax_option_type __flags)
+    {
+      size_t __len = __last - __first;
+      const auto* __cfirst = __len ? std::__addressof(*__first) : nullptr;
+      return __compile_nfa(__cfirst, __cfirst + __len, __traits, __flags);
+    }
+
   template<typename _TraitsT>
     struct _AnyMatcher
     {