小编Joh*_*hny的帖子

哪些IDE和文本编辑器可以推断出在C++ 11中使用auto关键字声明的变量类型

"几乎总是自动"一文中,Herb Sutter列出了使用auto关键字声明变量的几个原因.

他说实际变量类型可以由IDE自动推导出来,并通过将鼠标悬停在变量名称上来显示.

我想知道哪些IDE和文本编辑器(或插件)目前支持"自动"变量类型演绎.

编辑:

来自答案的IDE列表:

  • Visual Studio 201x
  • 日食
  • Qt Creator 2.7.0
  • KDevelop 4.5.1

文字编辑

那么Vim,Emacs,Sublime Text等等 - 有插件支持类型演绎吗?

c++ ide editor auto c++11

12
推荐指数
1
解决办法
2671
查看次数

模板__host__ __device__调用主机定义的函数

在实现CUDA代码期间,我经常需要一些实用程序函数,这些函数将从设备和主机代码中调用.所以我将这些函数声明为__host__ __device__.这是可以的,#ifdef CUDA_ARCH可以处理可能的设备/主机不兼容性.

当效用函数被模板化时出现问题,即.通过一些仿函数类型.如果模板实例调用__host__函数,我会收到此警告:

calling a __host__ function from a __host__ __device__ function is not allowed
      detected during instantiation of "int foo(const T &) [with T=HostObject]" 
Run Code Online (Sandbox Code Playgroud)

我知道的唯一解决方案是定义函数两次 - 一次用于设备,一次用于具有不同名称的主机代码(我不能重载__host__ __device__).但这意味着存在代码重复和所有其他__host__ __device__将调用它的函数,也必须定义两次(甚至更多的代码重复).

简化示例:

#include <cuda.h>
#include <iostream>

struct HostObject {
    __host__ 
    int value() const { return 42; }
};

struct DeviceObject {
    __device__ 
    int value() const { return 3; }
};

template <typename T> 
__host__ __device__ 
int foo(const T …
Run Code Online (Sandbox Code Playgroud)

cuda

12
推荐指数
1
解决办法
4521
查看次数

在boost元组,zip_iterator等上使用std :: get和std :: tie

我有什么选择使用std::get<>()std::tie<>()与boost结构一起使用?

示例:我想使用基于范围的for循环来迭代几个容器.我可以实现zip使用的功能boost::zip_iterator.

 #include <boost/iterator/zip_iterator.hpp>
 #include <boost/range.hpp>

 template <typename... TContainer>
 auto zip(TContainer&... containers) -> boost::iterator_range<boost::zip_iterator<decltype(boost::make_tuple(std::begin(containers)...))>> {
    auto zip_begin = boost::make_zip_iterator(boost::make_tuple(std::begin(containers)...));
    auto zip_end = boost::make_zip_iterator(boost::make_tuple(std::end(containers)...));
    return boost::make_iterator_range(zip_begin, zip_end);
 }
Run Code Online (Sandbox Code Playgroud)

现在我可以像这样使用它:

std:list<int> a;
std::vector<double> b;
...
for (auto t : zip(a, b)) {
   // access elements by boost::get<0>(t), boost::get<1>(t)
   // or use boost::tie(a_element, b_element)
}
Run Code Online (Sandbox Code Playgroud)

当我调用其他方法时会出现问题,std::tuple或者std::pair- 我必须转换),因为代码的其余部分使用std::tuples,或者模板化代码使用std::get<>()和/或std::tie().

我找到了一些增加std::tuple支持的补丁zip_iterator,但这些补丁并没有在我的版本中应用(我使用的是Boost 1.54).

我错过了什么吗?我的选择是要么力zip_iterator …

c++ boost stl tuples c++11

7
推荐指数
1
解决办法
1955
查看次数

在 CUDA 源文件上使用 clang-tidy

存在几种为 C/C++ 设计的静态分析工具,但它们对于测试 CUDA 源并不是特别有用。

由于clang 版本 6能够编译 CUDA,我想检查使用 clang-tidy 的选项,它似乎没有切换架构的选项。

有办法让它发挥作用吗?例如,用于打开 CUDA 解析器的编译时开关、自定义检查形式的扩展,或者可能是计划中的功能?

c++ static-analysis cuda clang clang-tidy

6
推荐指数
1
解决办法
1661
查看次数

标签 统计

c++ ×3

c++11 ×2

cuda ×2

auto ×1

boost ×1

clang ×1

clang-tidy ×1

editor ×1

ide ×1

static-analysis ×1

stl ×1

tuples ×1