lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] C++11 regex ctor arg inaccessible?


From: Greg Chicares
Subject: [lmi] C++11 regex ctor arg inaccessible?
Date: Sun, 15 May 2016 16:55:48 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0

While I was reviewing this:
  https://github.com/vadz/lmi/pull/16/
  Allow matching exception message substrings in BOOST_TEST_THROW
it occurred to me that if matching substrings is good, then matching
regular expressions would be better, e.g.:

  BOOST_TEST_THROW
    (throw (std::runtime_error("abc DEF ghi")
    ,std::runtime_error
    ,std::regex("DEF"));

Implementation seems trivial:

  bool it_matches(std::string const& observed, std::regex const& expected)
  {return regex_search(observed, expected);}

except for one thing: how can I print an informative error message if
the regex doesn't match? E.g.:

  std::cerr
    << "exception.what(), i.e. " << observed
    << "failed to match the regex " << expected
    << std::endl;

Apparently that can't be done:

  error: no match for 'operator<<'
    (operand types are 'std::basic_ostream<char>'
    and 'std::regex {aka std::basic_regex<char>}')

and there doesn't seem to be an accessor for basic_regex's argument like:

  std::string basic_regex::get_pattern() const

Even more surprisingly, I've tried web searches for "regex" plus various
terms like "extractor", "ostream", "pattern string", and I can't even
find evidence that anyone has ever asked about this; surely I'm not the
first? Am I missing something obvious?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]