小编use*_*878的帖子

C++头文件没有包含任何其他头文件的任何充分理由?

我已经看到一个标题包含这样的样式,其中头文件不包含其他头文件,相应的*.cpp文件必须包含所有依赖项(并按正确的顺序包含它们).在过去的好日子里,这可能会使构建依赖性跟踪变得更容易(但我只是在猜测).现在有充好的理由吗?

档案"Bh":

#ifndef _B_h_
#define _B_h_

// Note we do not #include "A.h" that contains class A declaration.

class B
{
public:
   A a; // An A object.
};
#endif // _B_h_
Run Code Online (Sandbox Code Playgroud)

文件"B.cpp":

#include "A.h" // Must include this before B.h, otherwise class A not defined in B.h
#include "B.h"

...
Run Code Online (Sandbox Code Playgroud)

c++ coding-style header-files

6
推荐指数
2
解决办法
2166
查看次数

为什么 std::all_of() 的编码版本与调用 std::all_of() 的基准测试不同?

Andrei Alexandrescu 在 2015 年 code::dive 会议“编写快速代码”演讲中受到了启发:https : //www.youtube.com/watch?v=vrfYLlR8X8k

我采用了 llvm std::all_of 代码,并针对直接调用 std::all_of() 对其进行了基准测试。我使用了 google 基准测试,以及 0 - 65535 个元素的范围(都满足谓词):

#include <benchmark/benchmark.h>

#include <algorithm>

// LLVM std::all_of copied from https://github.com/llvm-mirror/libcxx/blob/master/include/algorithm. Benchmarking this against a direct call to std::all_of().
template <class _InputIterator, class _Predicate>
inline bool
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
  for (; __first != __last; ++__first)
    if (!__pred(*__first))
      return false;
  return true;
}

static bool equals_42(int i)
{
    return i == 42;
}

// Benchmark for …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm benchmarking gcc clang

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

c ++ 14 std :: experimental :: filesystem :: v1和c ++ 17 std :: filesystem之间的区别?

我找到了这个页面,描述了c ++ 14和c ++ 17之间的变化:

https://isocpp.org/files/papers/p0636r0.html

...它链接到此页面,该页面描述了建议的文件系统更改:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0218r0.html

我浏览了它.也有小的措辞改变为标准,但唯一的代码改变我看到的是那个去掉了"实验"和"V1"部分命名空间的变化,所以"的std ::实验::文件系统:: V1"变成了"的std ::文件系统",这是预料之中的.

据我所知,命名空间路径以外的任何内容都没有改变.有没有人知道是否有其他变化?

换句话说,我正在使用gcc和-std = c ++ 14.我现在可以用std :: experimental :: filesystem编写代码,并且将来只需更改这个命名空间就可以轻松切换到-std = c ++ 17吗?

我可以找到最重要的问题是重复:

Boost文件系统和标准C++文件系统库有多相似?

现代C++的实验性功能是否可靠用于长期项目?

c++ c++14 c++17

4
推荐指数
1
解决办法
1222
查看次数

标签 统计

c++ ×3

algorithm ×1

benchmarking ×1

c++14 ×1

c++17 ×1

clang ×1

coding-style ×1

gcc ×1

header-files ×1