c++ - 可以使 declval 不为 Visual Studio 2010 返回不正确的类型
问题描述
我有以下代码并尝试在 Visual Studio 2010 中编译它。我必须支持旧客户,因此目前无法升级。
#include <boost/utility.hpp>
#include <boost/static_assert.hpp>
#include <type_traits>
struct Foo {
static Foo CreateFoo(int p){return Foo();}
};
template <typename F, typename A0>
struct ResultOf {
typedef decltype(boost::declval<F>()(boost::declval<A0>())) Type;
};
typedef ResultOf<decltype(&Foo::CreateFoo),int>::Type ResultType;
BOOST_STATIC_ASSERT(!std::is_reference<ResultType>::value);
静态断言失败,因为返回的是引用类型而不是值类型。
我知道 Visual Studio 2010 decltype 支持是粗略的。但是是否可以仅通过修改 decltype 表达式来使上述工作正常
typedef decltype(boost::declval<F>()(boost::declval<A0>())) ResultType;
我只需要对接受一个参数并返回值或引用的函数提供可靠的支持。
我还注意到,如果 CreateFoo 是一个自由函数而不是 Foo 的静态方法,那么代码就会编译。如果我找不到更好的东西,它们可能是一种解决方法。
解决方案
推荐阅读
- python - 如何在熊猫中只设置时间时间戳?
- python - 从高于我们的版本号的版本号进行脱酸
- java - 为什么 Spring 事务管理的传播级别“REQURIES_NEW”不起作用?
- python - 使用deap预处理文件进行情感分析
- spss-modeler - 使用 python 执行的 SPSS 流
- regex - .htaccess 重定向 - *.html 到 wordpress url 的正则表达式
- oracle - 错误,在选择过程中?如何解决这个问题?
- c++ - 遍历抽象类的向量
- c++ - 嵌套模板类的模板类模板参数的特化
- android - 如何使用字符串资源而不是硬编码字符串来设置 ViewPager 选项卡标题