Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++.moderated > #7416 > unrolled thread

Manipulating std::match_results?

Started byHergen Lehmann <hlehmann.expires.5-11@snafu.de>
First post2016-04-04 17:44 -0600
Last post2016-04-05 08:19 -0600
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c++.moderated


Contents

  Manipulating std::match_results? Hergen Lehmann <hlehmann.expires.5-11@snafu.de> - 2016-04-04 17:44 -0600
    Re: Manipulating std::match_results? Martin Bonner <martinfrompi@yahoo.co.uk> - 2016-04-05 08:19 -0600
    Re: Manipulating std::match_results? guy.tristram@googlemail.com - 2016-04-05 08:19 -0600

#7416 — Manipulating std::match_results?

FromHergen Lehmann <hlehmann.expires.5-11@snafu.de>
Date2016-04-04 17:44 -0600
SubjectManipulating std::match_results?
Message-ID<c55btc-e89.ln1@hergen.dyndns.org>
Hello,

i am currently in the process of refactoring some old code into 
c++11/14. Part of that code is a regex-like pattern matching mechanism, 
which (due to compatibility reasons) should be kept in place for now.

However, in preparation of a future transition to std::regex, i would 
like to go ahead, and store the results in a std::match_results object.

Unfortunately, i can't find any setter methods or constructors in this 
class, except for the default and copy constructors. Is there any 
(preferably portable) way to set the contents (sub-matches, prefix, 
suffix) of a std::match_results object without going through 
std::basic_regex?

TIA,
Hergen


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[toc] | [next] | [standalone]


#7417

FromMartin Bonner <martinfrompi@yahoo.co.uk>
Date2016-04-05 08:19 -0600
Message-ID<52f3ca74-f108-405c-b864-b6b7d779eade@googlegroups.com>
In reply to#7416
On Tuesday, 5 April 2016 00:50:13 UTC+2, Hergen Lehmann  wrote:
> Hello,
> 
> i am currently in the process of refactoring some old code into 
> c++11/14. Part of that code is a regex-like pattern matching mechanism, 
> which (due to compatibility reasons) should be kept in place for now.
> 
> However, in preparation of a future transition to std::regex, i would 
> like to go ahead, and store the results in a std::match_results object.
> 
> Unfortunately, i can't find any setter methods or constructors in this 
> class, except for the default and copy constructors. Is there any 
> (preferably portable) way to set the contents (sub-matches, prefix, 
> suffix) of a std::match_results object without going through 
> std::basic_regex?

I think you will find that setter methods are regarded as implementation
details, and so are not standardized.

I think your best bet is to write a class with an interface like
std::match_results, and then make rigorous use of `auto` in the calling
code so you can just swap in the standard class later.  (Alternatively, use
a typedef that can be toggled).


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[toc] | [prev] | [next] | [standalone]


#7418

Fromguy.tristram@googlemail.com
Date2016-04-05 08:19 -0600
Message-ID<ce9f408a-b66a-40e7-bc1d-54c6e672176f@googlegroups.com>
In reply to#7416
{ quoted server banner redacted. -mod }

On Monday, April 4, 2016 at 11:50:13 PM UTC+1, Hergen Lehmann wrote:
> Hello,
> 
> i am currently in the process of refactoring some old code into 
> c++11/14. Part of that code is a regex-like pattern matching mechanism, 
> which (due to compatibility reasons) should be kept in place for now.
> 
> However, in preparation of a future transition to std::regex, i would 
> like to go ahead, and store the results in a std::match_results object.
> 
> Unfortunately, i can't find any setter methods or constructors in this 
> class, except for the default and copy constructors. Is there any 
> (preferably portable) way to set the contents (sub-matches, prefix, 
> suffix) of a std::match_results object without going through 
> std::basic_regex?
> 
> TIA,
> Hergen
> 

I don't think so. From: http://en.cppreference.com/w/cpp/regex/match_results

This is a specialized allocator-aware container. It can only be default
created, obtained from std::regex_iterator, or modified by std::regex_search
or std::regex_match.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++.moderated


csiph-web