diff --git a/include/boost/regex/v5/match_results.hpp b/include/boost/regex/v5/match_results.hpp index 3f9cd012..6b77ea57 100644 --- a/include/boost/regex/v5/match_results.hpp +++ b/include/boost/regex/v5/match_results.hpp @@ -97,15 +97,23 @@ public: bool empty() const { return m_subs.size() < 2; } // element access: - difference_type length(int sub = 0) const +private: + difference_type do_get_length(int sub = 0) const { - if(m_is_singular) + if (m_is_singular) raise_logic_error(); sub += 2; - if((sub < (int)m_subs.size()) && (sub > 0)) + if ((sub < (int)m_subs.size()) && (sub > 0)) return m_subs[sub].length(); return 0; } +public: + template + typename std::enable_if::value, difference_type>::type length(Integer sub) const + { + return do_get_length(static_cast(sub)); + } + difference_type length() const { return do_get_length(0); } difference_type length(const char_type* sub) const { if(m_is_singular) @@ -161,7 +169,8 @@ public: { return position(sub.c_str()); } - string_type str(int sub = 0) const +private: + string_type do_get_string(int sub = 0) const { if(m_is_singular) raise_logic_error(); @@ -177,6 +186,13 @@ public: } return result; } +public: + template + typename std::enable_if::value, string_type>::type str(Integer sub) const + { + return do_get_string(static_cast(sub)); + } + string_type str() const { return do_get_string(0); } string_type str(const char_type* sub) const { return (*this)[sub].str(); @@ -196,7 +212,8 @@ public: { return (*this)[sub].str(); } - const_reference operator[](int sub) const + private: + const_reference get_at(int sub) const { if(m_is_singular && m_subs.empty()) raise_logic_error(); @@ -207,6 +224,12 @@ public: } return m_null; } +public: + template + typename std::enable_if::value, const_reference>::type operator[](Integer sub) const + { + return get_at(static_cast(sub)); + } // // Named sub-expressions: //