8

我一直在尝试让 boost.multiprecision 在我的 VC2017 项目中工作时遇到问题,并且我试图使最简单的项目成为可能作为概念证明:

#include<boost/multiprecision/cpp_int.hpp>

int main() {
    boost::multiprecision::cpp_int val{ 5 };
    val *= 5;
    val *= 5;
    return val.convert_to<int>();
}

不幸的是,此代码无法编译,并出现以下错误:

1>------ Build started: Project: Multiprecision Test, Configuration: Debug x64 ------
1>Multi Main.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(467): note: see reference to class template instantiation 'boost::numeric::convdetail::trivial_converter_impl<Traits>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(454): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(497): note: see reference to class template instantiation 'boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(475): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(526): note: see reference to class template instantiation 'boost::numeric::convdetail::non_rounding_converter<Traits,RangeChecker,RawConverter>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(505): error C2518: keyword 'typename' illegal in base class list; ignored
1>Done building project "Multiprecision Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

这些是我在最初使用 boost.multiprecision 的更复杂的项目中遇到的完全相同的错误。我在 Visual Studio 2015 中编译这段代码没有问题。有谁知道出了什么问题,我需要做些什么来修复它?

编辑:

使用 boost.asio 的项目编译没有问题:

#include<boost/asio.hpp>
#include<iostream>

int main() {
    boost::asio::io_service service;
    for (int i = 0; i < 10; i++) {
        service.post([i] {
            std::cout << i << std::endl;
        });
    }
    service.run();
    system("pause");
    return 0;
}
4

1 回答 1

18

该问题是由于某些模板在boost::multiprecision使用中引起的,该模板std::unary_function自 C++11 以来已被弃用,并已从 C++17 的标准中删除。

MSVC 2015 中的标准库实现引入了#if _HAS_AUTO_PTR_ETC诸如此类已弃用定义之类的保护措施。它们1在新开关/std:c++14(默认)下默认设置为0,在/std:c++latest(新编译器开关自 2015 Update 3 起可用)下默认设置为。

因此,在boost 删除std::unary_function对. 因此,要么使用编译器选项设置它,要么在某些 PCH 中设置它,这是第一个包含在所有翻译单元或类似的东西中。/std:c++latest#define _HAS_AUTO_PTR_ETC 1

可以在Stephan T. Lavavej的这篇博文中找到对这些设置的详细描述,包括控制其他已弃用或删除的功能的其他防护。Visual C++ 更改历史 2003 - 2015似乎是 MSVC 中重大更改的官方列表,但不幸的是它并没有涵盖所有这些细节。通常,扫描Visual C++ 团队博客以查找来自 Stephan 的帖子将为您提供有关这些内容的最佳信息。

于 2017-02-04T14:01:05.637 回答