Skip to content

match_results has different parameter type compared to std::match_results #197

@zufuliu

Description

@zufuliu

this cause warnings when porting std::regex code to boost::regex: warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data.

difference_type length(int sub = 0) const
https://github.com/boostorg/regex/blob/develop/include/boost/regex/v5/match_results.hpp#L100
https://en.cppreference.com/w/cpp/regex/match_results/length

string_type str(int sub = 0) const
https://github.com/boostorg/regex/blob/develop/include/boost/regex/v5/match_results.hpp#L164
https://en.cppreference.com/w/cpp/regex/match_results/str

const_reference operator[](int sub) const
https://github.com/boostorg/regex/blob/develop/include/boost/regex/v5/match_results.hpp#L199
https://en.cppreference.com/w/cpp/regex/match_results/operator_at

I think it's better to use size_type sub as parameter as difference_type position(size_type sub = 0) const:
https://github.com/boostorg/regex/blob/develop/include/boost/regex/v5/match_results.hpp#L131
https://en.cppreference.com/w/cpp/regex/match_results/position

and C-style cast inside these int sub functions can be avoided:

- if(sub < (int)m_subs.size() && (sub > 0))
+ if(sub < m_subs.size())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions