使用 C++ VC++ 中的技术报告 1 (TR1) 2010年

发布于 2024-09-18 15:20:26 字数 41 浏览 4 评论 0原文

如何在 Visual C++ 2010 中使用 C++ TR1 库?

How do I use a C++ TR1 library in visual c++ 2010?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薆情海 2024-09-25 15:20:26

VS2010 内置了一些 C++0x 功能。 TR1 的某些功能(例如数学函数)不包含在 TR1 的 Visual C++ 实现中。

boost 有 TR1 的实现,你可以得到通过下载 boost 来实现。

要从 VS2010 禁用 C++0x/TR1 标头并使用 boost 实现,请在 VS2010 项目的项目设置中定义 _HAS_CPP0X=0

VS2010 comes with a few C++0x features built-in. Some features of TR1, such as the mathematical functions, are not included in the Visual C++ implementation of TR1.

boost has an implementation of TR1, you can get it by downloading boost.

To disable the C++0x/TR1 headers from VS2010 and use the boost implementation, define _HAS_CPP0X=0 in the project settings for your VS2010 project.

零時差 2024-09-25 15:20:26

如果您想使用与 VS10 一起打包的 TR1 实现,只需 #include 您需要的标头即可开始运行。并非所有 TR1 都包含在 TR1 的 VS10 实现中。您可以找到工厂提供的实现中包含 TR1 的哪些部分(以及整个 C++0x)的列表 这里,这是一个如何在 VS10 中使用正则表达式的简单示例,取自 MSDN 示例页面

// std_tr1__regex__regex_search.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 

int main() 
    { 
    const char *first = "abcd"; 
    const char *last = first + strlen(first); 
    std::cmatch mr; 
    std::regex rx("abc"); 
    std::regex_constants::match_flag_type fl = 
        std::regex_constants::match_default; 

    std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha 
        << regex_search(first, first + 1, rx, fl) << std::endl; 

    std::cout << "search(f, l, \"abc\") == " << std::boolalpha 
        << regex_search(first, last, mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 

    std::cout << "search(\"a\", \"abc\") == " << std::boolalpha 
        << regex_search("a", rx) << std::endl; 

    std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha 
        << regex_search("xabcd", mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 

    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(std::string("a"), rx) << std::endl; 

    std::string str("abcabc"); 
    std::match_results<std::string::const_iterator> mr2; 
    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(str, mr2, rx) << std::endl; 
    std::cout << "  matched: \"" << mr2.str() << "\"" << std::endl; 

    return (0); 
    } 

If you want to use the implementation of TR1 that is packaged with VS10, it is a simple matter of simply #including the headers you need and hit the ground running. Not all of TR1 is included in the VS10 implementation of TR1. You can find a list of which parts of TR1 (and C++0x as a whole) are included in the factory-supplied implementation here, and here is a simplistic example of how to use regexes in VS10 as taken from an MSDN sample page:

// std_tr1__regex__regex_search.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 

int main() 
    { 
    const char *first = "abcd"; 
    const char *last = first + strlen(first); 
    std::cmatch mr; 
    std::regex rx("abc"); 
    std::regex_constants::match_flag_type fl = 
        std::regex_constants::match_default; 

    std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha 
        << regex_search(first, first + 1, rx, fl) << std::endl; 

    std::cout << "search(f, l, \"abc\") == " << std::boolalpha 
        << regex_search(first, last, mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 

    std::cout << "search(\"a\", \"abc\") == " << std::boolalpha 
        << regex_search("a", rx) << std::endl; 

    std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha 
        << regex_search("xabcd", mr, rx) << std::endl; 
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 

    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(std::string("a"), rx) << std::endl; 

    std::string str("abcabc"); 
    std::match_results<std::string::const_iterator> mr2; 
    std::cout << "search(string, \"abc\") == " << std::boolalpha 
        << regex_search(str, mr2, rx) << std::endl; 
    std::cout << "  matched: \"" << mr2.str() << "\"" << std::endl; 

    return (0); 
    } 
征﹌骨岁月お 2024-09-25 15:20:26

与 GCC 不同,VC2010 中的 TR1 标头并未隔离在 TR1/ 目录中。我知道这一点不是通过使用 VC,而是因为有人告诉我 GCC 的实现在这种方式上是不寻常的。

N1836 1.3/4:

建议使用默认情况下未定义的宏来保护标准标头中的附加声明,或者将所有扩展标头(包括新标头和具有非标准声明的标准标头的并行版本)放置在不属于默认搜索路径的单独目录。

因此,您可能还需要添加#define。不幸的是他们没有对此进行标准化!

Unlike GCC, the TR1 headers in VC2010 are not sequestered in a TR1/ directory. I know this not from using VC but because someone told me that GCC's implementation is unusual in this fashion.

N1836 1.3/4:

It is recommended either that additional declarations in standard headers be protected with a macro that is not defined by default, or else that all extended headers, including both new headers and parallel versions of standard headers with nonstandard declarations, be placed in a separate directory that is not part of the default search path.

So, you might also need add a #define. It is unfortunate that they didn't standardize this!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文