Skip to content

Commit c82a797

Browse files
committed
Suppress conversion warnings in match_results.
When passing std::size_t arguments to length(), str() and operator[] by making these templates enable_if'd on is_integral. Fixes #197.
1 parent 260982e commit c82a797

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

include/boost/regex/v5/match_results.hpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,23 @@ class match_results
9797
bool empty() const
9898
{ return m_subs.size() < 2; }
9999
// element access:
100-
difference_type length(int sub = 0) const
100+
private:
101+
difference_type do_get_length(int sub = 0) const
101102
{
102-
if(m_is_singular)
103+
if (m_is_singular)
103104
raise_logic_error();
104105
sub += 2;
105-
if((sub < (int)m_subs.size()) && (sub > 0))
106+
if ((sub < (int)m_subs.size()) && (sub > 0))
106107
return m_subs[sub].length();
107108
return 0;
108109
}
110+
public:
111+
template <class Integer>
112+
typename std::enable_if<std::is_integral<Integer>::value, difference_type>::type length(Integer sub) const
113+
{
114+
return do_get_length(static_cast<int>(sub));
115+
}
116+
difference_type length() const { return do_get_length(0); }
109117
difference_type length(const char_type* sub) const
110118
{
111119
if(m_is_singular)
@@ -161,7 +169,8 @@ class match_results
161169
{
162170
return position(sub.c_str());
163171
}
164-
string_type str(int sub = 0) const
172+
private:
173+
string_type do_get_string(int sub = 0) const
165174
{
166175
if(m_is_singular)
167176
raise_logic_error();
@@ -177,6 +186,13 @@ class match_results
177186
}
178187
return result;
179188
}
189+
public:
190+
template <class Integer>
191+
typename std::enable_if<std::is_integral<Integer>::value, string_type>::type str(Integer sub) const
192+
{
193+
return do_get_string(static_cast<int>(sub));
194+
}
195+
string_type str() const { return do_get_string(0); }
180196
string_type str(const char_type* sub) const
181197
{
182198
return (*this)[sub].str();
@@ -196,7 +212,8 @@ class match_results
196212
{
197213
return (*this)[sub].str();
198214
}
199-
const_reference operator[](int sub) const
215+
private:
216+
const_reference get_at(int sub) const
200217
{
201218
if(m_is_singular && m_subs.empty())
202219
raise_logic_error();
@@ -207,6 +224,12 @@ class match_results
207224
}
208225
return m_null;
209226
}
227+
public:
228+
template <class Integer>
229+
typename std::enable_if<std::is_integral<Integer>::value, const_reference>::type operator[](Integer sub) const
230+
{
231+
return get_at(static_cast<int>(sub));
232+
}
210233
//
211234
// Named sub-expressions:
212235
//

0 commit comments

Comments
 (0)