template<typename, typename, typename, bool>
class _Executor;
+
+ template<typename _Tp>
+ struct __is_contiguous_iter : false_type { };
+
+ template<typename _Tp>
+ struct __is_contiguous_iter<_Tp*> : true_type { };
+
+ template<typename _Tp, typename _Cont>
+ struct __is_contiguous_iter<__gnu_cxx::__normal_iterator<_Tp*, _Cont>>
+ : true_type { };
}
_GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
explicit
basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
- : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f)
- { }
+ { _M_compile(__p, __p + _Rx_traits::length(__p), __f); }
/**
* @brief Constructs a basic regular expression from the sequence
*/
basic_regex(const _Ch_type* __p, std::size_t __len,
flag_type __f = ECMAScript)
- : basic_regex(__p, __p + __len, __f)
- { }
+ { _M_compile(__p, __p + __len, __f); }
/**
* @brief Copy-constructs a basic regular expression.
basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
_Ch_alloc>& __s,
flag_type __f = ECMAScript)
- : basic_regex(__s.data(), __s.data() + __s.size(), __f)
- { }
+ { _M_compile(__s.data(), __s.data() + __s.size(), __f); }
/**
* @brief Constructs a basic regular expression from the range
template<typename _FwdIter>
basic_regex(_FwdIter __first, _FwdIter __last,
flag_type __f = ECMAScript)
- : basic_regex(std::move(__first), std::move(__last), locale_type(), __f)
- { }
+ { this->assign(__first, __last, __f); }
/**
* @brief Constructs a basic regular expression from an initializer list.
* @throws regex_error if @p __l is not a valid regular expression.
*/
basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
- : basic_regex(__l.begin(), __l.end(), __f)
- { }
+ { _M_compile(__l.begin(), __l.end(), __f); }
/**
* @brief Destroys a basic regular expression.
* @brief Assigns one regular expression to another.
*/
basic_regex&
- operator=(const basic_regex& __rhs)
- { return this->assign(__rhs); }
+ operator=(const basic_regex&) = default;
/**
* @brief Move-assigns one regular expression to another.
*/
basic_regex&
- operator=(basic_regex&& __rhs) noexcept
- { return this->assign(std::move(__rhs)); }
+ operator=(basic_regex&&) = default;
/**
* @brief Replaces a regular expression with a new one constructed from
*/
basic_regex&
operator=(initializer_list<_Ch_type> __l)
- { return this->assign(__l.begin(), __l.end()); }
+ { return this->assign(__l); }
/**
* @brief Replaces a regular expression with a new one constructed from
// [7.8.3] assign
/**
- * @brief the real assignment operator.
+ * @brief Assigns one regular expression to another.
*
* @param __rhs Another regular expression object.
*/
basic_regex&
- assign(const basic_regex& __rhs)
- {
- basic_regex __tmp(__rhs);
- this->swap(__tmp);
- return *this;
- }
+ assign(const basic_regex& __rhs) noexcept
+ { return *this = __rhs; }
/**
- * @brief The move-assignment operator.
+ * @brief Move-assigns one regular expression to another.
*
* @param __rhs Another regular expression object.
*/
basic_regex&
assign(basic_regex&& __rhs) noexcept
- {
- basic_regex __tmp(std::move(__rhs));
- this->swap(__tmp);
- return *this;
- }
+ { return *this = std::move(__rhs); }
/**
* @brief Assigns a new regular expression to a regex object from a
*/
basic_regex&
assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
- { return this->assign(string_type(__p), __flags); }
+ {
+ _M_compile(__p, __p + _Rx_traits::length(__p), __flags);
+ return *this;
+ }
/**
* @brief Assigns a new regular expression to a regex object from a
// 3296. Inconsistent default argument for basic_regex<>::assign
basic_regex&
assign(const _Ch_type* __p, size_t __len, flag_type __flags = ECMAScript)
- { return this->assign(string_type(__p, __len), __flags); }
+ {
+ _M_compile(__p, __p + __len, __flags);
+ return *this;
+ }
/**
* @brief Assigns a new regular expression to a regex object from a
assign(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s,
flag_type __flags = ECMAScript)
{
- return this->assign(basic_regex(__s.data(), __s.data() + __s.size(),
- _M_loc, __flags));
+ _M_compile(__s.data(), __s.data() + __s.size(), __flags);
+ return *this;
}
/**
basic_regex&
assign(_InputIterator __first, _InputIterator __last,
flag_type __flags = ECMAScript)
- { return this->assign(string_type(__first, __last), __flags); }
+ {
+#if __cplusplus >= 201703L
+ using _ValT = typename iterator_traits<_InputIterator>::value_type;
+ if constexpr (__detail::__is_contiguous_iter<_InputIterator>::value
+ && is_same_v<_ValT, value_type>)
+ {
+ const auto __len = __last - __first;
+ const _Ch_type* __p = std::__to_address(__first);
+ _M_compile(__p, __p + __len, __flags);
+ }
+ else
+#endif
+ this->assign(string_type(__first, __last), __flags);
+ return *this;
+ }
/**
* @brief Assigns a new regular expression to a regex object.
*/
basic_regex&
assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
- { return this->assign(__l.begin(), __l.end(), __flags); }
+ {
+ _M_compile(__l.begin(), __l.end(), __flags);
+ return *this;
+ }
// [7.8.4] const operations
/**
private:
typedef std::shared_ptr<const __detail::_NFA<_Rx_traits>> _AutomatonPtr;
- template<typename _FwdIter>
- basic_regex(_FwdIter __first, _FwdIter __last, locale_type __loc,
- flag_type __f)
- : _M_flags(__f), _M_loc(std::move(__loc)),
- _M_automaton(__detail::__compile_nfa<_Rx_traits>(
- std::move(__first), std::move(__last), _M_loc, _M_flags))
- { }
+ void
+ _M_compile(const _Ch_type* __first, const _Ch_type* __last,
+ flag_type __f)
+ {
+ __detail::_Compiler<_Rx_traits> __c(__first, __last, _M_loc, __f);
+ _M_automaton = __c._M_get_nfa();
+ _M_flags = __f;
+ }
template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
__detail::_RegexExecutorPolicy, bool>
const _CtypeT& _M_ctype;
};
- template<typename _Tp>
- struct __is_contiguous_iter : is_pointer<_Tp>::type { };
-
- template<typename _Tp, typename _Cont>
- struct
- __is_contiguous_iter<__gnu_cxx::__normal_iterator<_Tp*, _Cont>>
- : true_type { };
-
- template<typename _Iter, typename _TraitsT>
- using __enable_if_contiguous_iter
- = __enable_if_t< __is_contiguous_iter<_Iter>::value,
- std::shared_ptr<const _NFA<_TraitsT>> >;
-
- template<typename _Iter, typename _TraitsT>
- using __disable_if_contiguous_iter
- = __enable_if_t< !__is_contiguous_iter<_Iter>::value,
- std::shared_ptr<const _NFA<_TraitsT>> >;
-
- template<typename _TraitsT, typename _FwdIter>
- inline __enable_if_contiguous_iter<_FwdIter, _TraitsT>
- __compile_nfa(_FwdIter __first, _FwdIter __last,
- const typename _TraitsT::locale_type& __loc,
- regex_constants::syntax_option_type __flags)
- {
- size_t __len = __last - __first;
- const auto* __cfirst = __len ? std::__addressof(*__first) : nullptr;
- using _Cmplr = _Compiler<_TraitsT>;
- return _Cmplr(__cfirst, __cfirst + __len, __loc, __flags)._M_get_nfa();
- }
-
- template<typename _TraitsT, typename _FwdIter>
- inline __disable_if_contiguous_iter<_FwdIter, _TraitsT>
- __compile_nfa(_FwdIter __first, _FwdIter __last,
- const typename _TraitsT::locale_type& __loc,
- regex_constants::syntax_option_type __flags)
- {
- const basic_string<typename _TraitsT::char_type> __str(__first, __last);
- return __compile_nfa<_TraitsT>(__str.data(), __str.data() + __str.size(),
- __loc, __flags);
- }
-
// [28.13.14]
template<typename _TraitsT, bool __icase, bool __collate>
class _RegexTranslatorBase