2017-07-14 4 views
1

boost::regexでコーディングしていて、C++ 11のstd::regexと同じ結果が得られないようです。boost :: regexとstd :: regexの間に不一致がありますか?

は、簡単なコードを次の点を考慮

#include <string> 
#include <iostream> 
#if defined(_MSC_VER) || (__cplusplus >= 201103L) 
#include <regex> 
#else // defined(_MSC_VER) || (__cplusplus >= 201103L) 
#include <boost/regex.hpp> 
#endif // defined(_MSC_VER) || (__cplusplus >= 201103L) 

namespace { 
#if defined(_MSC_VER) || (__cplusplus >= 201103L) 
using std::regex; 
using std::regex_replace; 
#else // defined(_MSC_VER) || (__cplusplus >= 201103L) 
using boost::regex; 
using boost::regex_replace; 
#endif // defined(_MSC_VER) || (__cplusplus >= 201103L) 
} // namespace 

int main() { 
    std::string input = "abc.txt"; 
    ::regex re("[.]", ::regex::extended); 

    std::string output = ::regex_replace(input, re, "\\."); 

    std::cout << "Result : " << output << "\n"; 
    return 0; 
} 

C++ 11バージョン(GCC 5.4、GCC 8.0 in wandbox、MSVC 2015)Result : abc\.txtブースト1.64バージョン(GCC 8.0 in wandbox)と

しかし、C++ 03与えを与えますResult : abc.txt

また、::regex::ECMAScriptの代わりに::regex::extendedにしようとしましたが、それらは同じです。

boost::regexstd::regexから不明 MAGIC矛盾がありますか?

答えて

1

は、私はそれが審議されていないかわかりません。 regex_replaceの4番目のパラメータとして使用できるboost::regex_constants::format_literalがあると、std :: regex_replaceと同じ結果が得られます。しかし、標準のC++ライブラリにはformat_literalはありません。

+0

私はそのようなオプションの事項を知りませんでした!ありがとう@ああ明 –