Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:30:01+00:00 2026-05-15T03:30:01+00:00

I have a code that has been working for almost 4 years (since boost

  • 0

I have a code that has been working for almost 4 years (since boost 1.33) and today I went from boost 1.36 to boost 1.42 and now I have a problem.

I’m calling a custom formatter on a string to format parts of the string that match a REGEX.

For instance, a string like: “abc;def:” will be changed to “abc\2Cdef\3B” if the REGEX contains “([;:])”

boost::find_format_all( mystring, boost::regex_finder( REGEX ), custom_formatter() );

The custom formatter looks like this:

struct custom_formatter()
{

  template< typename T >
  std::string operator()( const T & s ) const
  {
      std::string matchStr = s.match_results().str(1);

      // perform substitutions

      return matchStr;
  }

}

This worked fine but with boost 1.42 I know have “non initialized” s.match_results() which yield to boost::exception_detail::clone_implINS0_::error_info_injectorISt11logic_errorEEEE
– Attempt to access an uninitialzed boost::match_results<> class.

This means that sometimes I am in the functor to format a string but there is no match.

Am I doing something wrong? Or is it normal to enter the functor when there is no match and I should check against something?

for now my solution is to try{}catch(){} the exception and everything works fine, but somehow that doesn’t feel very good.

EDIT1

Actually I have a new empty match at the end of each string to parse.

EDIT2 : one solution inspired by ablaeul

  template< typename T >
  std::string operator()( const T & s ) const
  {

      if( s.begin() == s.end() ) return std::string();

      std::string matchStr = s.match_results().str(1);

      // perform substitutions

      return matchStr;
  }

EDIT3 Seems to be a bug in (at least) boost 1.42

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:30:02+00:00Added an answer on May 15, 2026 at 3:30 am

    The struct find_regexF seems to be the culprit. As you can see, it returns an empty result with a uninitialized match_results(). Looking through SO found me the following solution:

    struct custom_formatter()
    {
    
      template< typename T >
      std::string operator()( const T & s ) const
      {
          std::string matchStr;
          for (typename T::const_iterator i = Match.begin();
                 i != Match.end();
                 i++) {
              // perform substitutions via *i
          }
          return matchStr;
      }
    
    }
    

    EDIT: Looking at how Boost uses the formatter here is another solution:

    template<typename InputIteratorT>
    std::string operator()( 
        const regex_search_result<InputIteratorT>& Replace ) const
    {
        if ( Replace.empty() )
        {
            return std::string();
        }
        else
        {
            std::string matchStr = s.match_results().str(1);
            // perform substitutions
            return matchStr;      
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 442k
  • Answers 442k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know about Dwoo, but you should be able… May 15, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer I just use constants. Eg AWS_PW = "ssss" you can… May 15, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer You can get the domain of the current page using… May 15, 2026 at 5:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.