C2143/C2518尝试使用boost.multiprecision编译项目时

Xir*_*ema 6 c++ boost boost-multiprecision visual-studio-2017

我一直在尝试使用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>();
}
Run Code Online (Sandbox Code Playgroud)

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

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 ==========
Run Code Online (Sandbox Code Playgroud)

这些是我在最初使用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;
}
Run Code Online (Sandbox Code Playgroud)

bog*_*dan 15

问题是由于某些模板正在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,您必须要么不使用/std:c++latest(我一直在使用它,因为它出来了)或者#define _HAS_AUTO_PTR_ETC 1包括(直接或间接)任何标准库头.因此,要么使用编译器选项设置,要么在某些PCH中设置,这是第一个包含在所有翻译单元或类似内容中的PCH.

这些设置的详尽描述,包括控制其他已弃用或删除功能的其他警卫,可以在Stephan T. Lavavej的博客文章中找到.在VISUAL C++改变历史2003年至2015年似乎是在MSVC重大更改的正式名单,但遗憾的是它并没有涵盖所有的这些细节.通常,扫描Visual C++团队博客以获取Stephan的帖子将为您提供有关这些内容的最佳信息.

  • @JeffreyFaust 我不知道,`std::` 不知何故感觉如此正确;-)。至少我是一贯的——我犯了两次同样的错误。谢谢,修好了。 (2认同)