标签: visual-c++-2012

Visual Studio 2012中的C++ 11功能

Visual Studio 2012的预览版(VS2010之后的下一个版本)现已推出.

有谁知道它支持哪些新的C++ 11功能?(我现在无法试一试).

c++ visual-c++ c++11 visual-c++-2012

94
推荐指数
4
解决办法
6万
查看次数

Lambda的显式返回类型

当我尝试编译此代码(VS2010)时,我收到以下错误: error C3499: a lambda that has been specified to have a void return type cannot return a value

void DataFile::removeComments()
{
  string::const_iterator start, end;
  boost::regex expression("^\\s?#");
  boost::match_results<std::string::const_iterator> what;
  boost::match_flag_type flags = boost::match_default;
  // Look for lines that either start with a hash (#)
  // or have nothing but white-space preceeding the hash symbol
  remove_if(rawLines.begin(), rawLines.end(), [&expression, &start, &end, &what, &flags](const string& line)
  {
    start = line.begin();
    end = line.end();
    bool temp = boost::regex_search(start, end, what, expression, flags);
    return temp; …
Run Code Online (Sandbox Code Playgroud)

c++ lambda visual-c++ c++11 visual-c++-2012

74
推荐指数
3
解决办法
9万
查看次数

否定数字的最快方法

我今天早上在这里思考,最好的方法是将一些积极转为负面,从消极转为正面,当然,最简单的方法可能是:

int a = 10;
a = a*(-1);
Run Code Online (Sandbox Code Playgroud)

要么

int a = 10;
a = -a;
Run Code Online (Sandbox Code Playgroud)

但是,我想,我接着这样做,使用命令shift和指针......真的可以使用命令移位运算符和内存来改变值的符号吗?

c c++ intel visual-c++-2012

33
推荐指数
4
解决办法
5万
查看次数

Visual C++ 2012(x86)中可能的编译器错误?

我正在使用VC++ 11(CTP Update 1)编译x86目标时遇到随机浮点错误.请参阅下面的简短示例"test.cpp",并使用以下命令进行编译:

cl /GL /O2 /EHsc test.cpp /link /MACHINE:X86
Run Code Online (Sandbox Code Playgroud)

输出应该是10 == 10,但它会10 == 0/GL(整个程序优化)启用时产生.问题似乎是get_scaling_factor()将结果推送到浮点堆栈,但调用函数期望它在SSE寄存器XMM0中.

问题:我错过了一些明显的东西,还是这真的是一个错误?当然,测试程序没有意义,因为它是一个简化的测试用例.

TEST.CPP:

#include <iostream>

template <typename T>
inline T get_scaling_factor(int units)
{
    switch (units)
    {
    case 0: return 1;  
    case 1: return 10;  
    case 2: return 100;  
    case 3: return 1000;  
    case 4: return 10000;  
    case 5: return 100000;  
    case 6: return 1000000;  
    case 7: return 10000000;  
    case 8: return 100000000; …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ compiler-bug visual-studio-2012 visual-c++-2012

29
推荐指数
1
解决办法
1933
查看次数

如果在使用VS2012 RC时main()退出后调用,则std :: thread :: join()会挂起

如果在Ubuntu 12.04上使用Clang 3.2或GCC 4.7进行编译,则以下示例成功运行(即不挂起),但如果我使用VS11 Beta或VS2012 RC进行编译,则会挂起.

#include <iostream>
#include <string>
#include <thread>
#include "boost/thread/thread.hpp"

void SleepFor(int ms) {
  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}

template<typename T>
class ThreadTest {
 public:
  ThreadTest() : thread_([] { SleepFor(10); }) {}
  ~ThreadTest() {
    std::cout << "About to join\t" << id() << '\n';
    thread_.join();
    std::cout << "Joined\t\t" << id() << '\n';
  }
 private:
  std::string id() const { return typeid(decltype(thread_)).name(); }
  T thread_;
};

int main() {
  static ThreadTest<std::thread> std_test;
  static ThreadTest<boost::thread> boost_test;
//  SleepFor(100);
}
Run Code Online (Sandbox Code Playgroud)

问题似乎是,std::thread::join()如果在main …

c++ visual-c++ c++11 stdthread visual-c++-2012

23
推荐指数
2
解决办法
9910
查看次数

解决错误R6016 - 没有足够的空间用于线程数据

我的静态链接Visual C++ 2012程序偶尔会生成一个CRTL错误:"R6016 - 没有足够的空间用于线程数据".

Microsoft的最小文档说,当生成新线程时会生成此错误消息,但是没有足够的内存可以为其分配.

但是,我的代码只在几个明确定义的情况下显式生成一个新线程,这两个都没有发生在这里(尽管Microsoft库内部确实产生了很好的线程).当程序刚刚存在于后台时,一个用户报告了此问题.

不确定它是否相关,但我还没有覆盖默认的1MB保留堆栈大小或堆大小,并且我的程序使用的总内存通常非常小(在具有12GB实际RAM的系统上为3MB-10MB,超过一半这是未分配的).

这很少发生(因此我无法追踪它),并且已在多台机器上报告.我在Windows 8.1上只听说过这个,但我不会读太多.

是否有某些编译器设置可能会影响此错误?还是编程错误?

windows multithreading visual-c++-2012

16
推荐指数
1
解决办法
5万
查看次数

VS 2012中的Variadic模板(Visual C++ 2012年11月CTP)

我安装了Visual C++编译器2012年11月CTP并创建了一个C++控制台项目.我写了这个

template<typename T>
void Test(T value){
}
template<typename T, typename... Args>
void Test(T value, Args... args){
    Test(value);
    Test(args...);
}

int main(){
    Test(1,2,3);
}
Run Code Online (Sandbox Code Playgroud)

然后我按下F6来构建IDE.我在第4行得到了这个错误

error C2143: syntax error : missing ',' before '...'
Run Code Online (Sandbox Code Playgroud)

编译列表"可变参数模板",所以我认为这应该工作.我知道intellisense可能是不正确的,但'编译器'应该工作.我可以不用IDE构建吗?我必须在某个地方启用某些东西吗?int i{4};似乎也没有工作,我相信这是有效的统一初始化.

c++ visual-c++ c++11 visual-c++-2012

13
推荐指数
1
解决办法
1万
查看次数

C++ lambdas没有正确选择重载函数吗?

我有一个迭代容器的函数,并将每个元素传递给谓词进行过滤.此函数的重载也会将每个元素的索引传递给谓词.

template<typename TContainer>
void DoSomethingIf(TContainer &c, std::function<bool (const typename TContainer::const_reference)> predicate);

template<typename TContainer>
void DoSomethingIf(TContainer &c, std::function<bool (const typename TContainer::const_reference, int)> predicate);
Run Code Online (Sandbox Code Playgroud)

我发现尝试使用裸lambda 调用这些函数中的任何一个将导致VC11中的编译器错误,而使用std :: function对象将成功:

void foo()
{
    std::vector<int> v;

    // fails
    DoSomethingIf(v, [](const int &x) { return x == 0; });

    // also fails
    auto lambda = [](const int &x) { return x == 0; };
    DoSomethingIf(v, lambda);

    // success!
    std::function<bool (const int &)> fn = [](const int &x) { return x == 0; };
    DoSomethingIf(v, …
Run Code Online (Sandbox Code Playgroud)

c++ lambda visual-c++ c++11 visual-c++-2012

12
推荐指数
2
解决办法
1652
查看次数

这里的循环依赖在哪里?

有没有人看到下面关于循环代码的任何明显的东西,我没有看到为什么这不能被VS2012的C++编译器自动矢量化?

所有编译器给我的是info C5002: loop not vectorized due to reason '1200'当我使用/Qvec-report:2命令行开关时.

原因1200在MSDN中记录为:

循环包含阻止矢量化的循环携带数据依赖性.循环的不同迭代相互干扰,使得对循环进行矢量化将产生错误的答案,并且自动矢量化器不能向自身证明不存在这样的数据依赖性.

我知道(或者我很确定)没有任何循环传输的数据依赖,但我不确定是什么阻止了编译器实现这一点.

这些sourcedest指针不会重叠,也不会为同一个内存设置别名,我正在尝试为编译器提供该提示__restrict.

pitch总是一个正整数值,类似于4096,取决于屏幕分辨率,因为这是一个8bpp-> 32bpp渲染/转换功能,逐列操作.

byte  * __restrict source;
DWORD * __restrict dest;
int pitch;

for (int i = 0; i < count; ++i) {
    dest[(i*2*pitch)+0] = (source[(i*8)+0]);
    dest[(i*2*pitch)+1] = (source[(i*8)+1]);
    dest[(i*2*pitch)+2] = (source[(i*8)+2]);
    dest[(i*2*pitch)+3] = (source[(i*8)+3]);

    dest[((i*2+1)*pitch)+0] = (source[(i*8)+4]);
    dest[((i*2+1)*pitch)+1] = (source[(i*8)+5]);
    dest[((i*2+1)*pitch)+2] = (source[(i*8)+6]);
    dest[((i*2+1)*pitch)+3] = (source[(i*8)+7]);
}
Run Code Online (Sandbox Code Playgroud)

每个周围的parens source[]都是函数调用的残余,我在这里已经省略了,因为在没有函数调用的情况下,循环仍然不会以最简单的形式自动向量化.

编辑:

我已经将循环简化为最简单的形式,我可以:

for …
Run Code Online (Sandbox Code Playgroud)

c++ vectorization compiler-optimization visual-c++ visual-c++-2012

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

C++ 11文件系统(VS2012)

我在查找vs2012所包含的标题上的任何文档时遇到了很多麻烦.我看到它在这里提到但它们没有提供如何使用它的链接.我真正想要的是如何使用它的文档,首选visual studio实现.谢谢

c++ visual-c++ c++11 visual-c++-2012 c++-tr2

10
推荐指数
1
解决办法
1万
查看次数