问题描述
当前,我的库使用boost :: optional和boost :: variant.由于C ++ 17已发布,因此我想添加一个选项,使其可以与boost和std一起使用.
Currently my library uses boost::optional and boost::variant. Since C++17 is out, I would like to add an option, that it works with the boost and std.
所以我测试了完整的代码,其中boost可选和variant以及std可选和variant成功.
So I tested the complete code with boost optional and variant and std optional and variant successful.
所以我添加了一个与此相似的头文件:
So I added a header files that is similar to this:
#ifdef USE_BOOST
#include <boost/optional.hpp>
#elif USE_STD
#include <optional>
#endif
namespace Foo {
#ifdef USE_BOOST
template <typename T>
using optional = boost::optional<T>
#elif USE_STD
template <typename T>
using optional = std::optional<T>
#endif
}
一切正常.
然后我为变体添加了类似的内容
Then I added something similar for variant
#ifdef USE_BOOST
#include <boost/variant.hpp>
#elif USE_STD
#include <variant>
#endif
namespace Foo {
#ifdef USE_BOOST
template <typename... T>
using variant = boost::variant<T...>
// similar to the following
#elif USE_STD
template <typename...T>
using variant = std::variant<T...>;
template <class T, class... Types>
constexpr T& get(std::variant<Types...>& v) {
return std::get<T>(v);
};
template <class T, class... Types>
constexpr T&& get(std::variant<Types...>&& v) {
return std::get<T>(std::move(v));
};
template <class T, class... Types>
constexpr const T& get(const std::variant<Types...>& v) {
return std::get<T>(v);
};
template <class T, class... Types>
constexpr const T&& get(const std::variant<Types...>&& v) {
return std::get<T>(std::move(v));
};
#endif
}
在库中,我现在到处都使用Foo :: optional和Foo :: variant.但是现在所有功能模板,例如
And within the library I use now everywhere Foo::optional and Foo::variant. But now all function templates like
template <typename... Args>
bool bar(const std::tuple<variant<Args,
std::exception_ptr>...>& args)
找不到
了. (c语错误消息:没有匹配的函数可以调用...)
are not found any more. (clang error message: no matching function for call to ...)
经过clang干线和VS 2017 15.6.1预览版测试有什么主意吗?
Tested with clang trunk and VS 2017 15.6.1 PreviewAny idea?
非常感谢!
我的要点
推荐答案
最后解决了问题.这是在VS中lang的错误. GCC编译就可以了. clang和VS的解决方案是使用显式模板参数调用该函数.
Finally problem solved. It is a bug in clang an VS. GCC compiles it fine. The solution for clang and VS is calling the function with explicit template parameters.
这篇关于混叠boost :: variant或std :: variant无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!