这是我在尝试将unique_ptr用于pimpl时所看到的简化.我选择了unique_ptr,因为我真的希望类拥有指针 - 我希望pimpl指针和类的生命周期相同.
无论如何,这是标题:
#ifndef HELP
#define HELP 1
#include <memory>
class Help
{
public:
Help(int ii);
~Help() = default;
private:
class Impl;
std::unique_ptr<Impl> _M_impl;
};
#endif // HELP
Run Code Online (Sandbox Code Playgroud)
这是来源:
#include "Help.h"
class Help::Impl
{
public:
Impl(int ii)
: _M_i{ii}
{ }
private:
int _M_i;
};
Help::Help(int ii)
: _M_impl{new Help::Impl{ii}}
{ }
Run Code Online (Sandbox Code Playgroud)
我可以将它们编译成一个库就好了.但是当我尝试在测试程序中使用它时,我得到了
ed@bad-horse:~/ext_distribution$ ../bin/bin/g++ -std=c++0x -o test_help test_help.cpp Help.cpp
In file included from /home/ed/bin/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/memory:86:0,
from Help.h:4,
from test_help.cpp:3:
/home/ed/bin/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = …
Run Code Online (Sandbox Code Playgroud) 为什么委员会将monotonic_clock重命名为stable_clock?供应商提供monotonic_clock以实现向后兼容性,因此我预计monotonic_clock将会停留一段时间.
在C++ 0x中弃用某些东西似乎有点早.;)编辑:委托人有权利和责任在发布之前尽可能地重命名组件,就像在这种情况下一样.
我没有看到重命名的好处.
我试图解决c ++中的旅行商问题,但我必须遍历一组poylgons而不是一组点之间的最短距离.为此,我试图通过代表性的"平均"内部点来表示每个多边形,以便我可以在这些平均内部点上执行TSP.
我很容易在凸多边形中找到一个平均内点,因为它只是算术平均点(并且总是位于凸多边形的内部),但这种方法不适用于凹多边形,因为它不一定在多边形的内部.
帮忙吗?谢谢.:-)
iota模板函数已添加到标准库中,以使用递增的值序列填充迭代器范围.
template<typename ForwardIterator, typename Tp>
void
iota(ForwardIterator first, ForwardIterator last, Tp value)
{
for (; first != last; ++first)
{
*first = value;
++value;
}
}
Run Code Online (Sandbox Code Playgroud)
大多数其他模板<numeric>
都有接受用户指定的运算符的版本.有这个:
template<typename ForwardIterator, typename Tp, typename Operator>
void
iota(ForwardIterator first, ForwardIterator last, Tp value, Operator op)
{
for (; first != last; ++first)
{
*first = value;
op(value);
}
}
Run Code Online (Sandbox Code Playgroud)
如果你不想(或不能)为Tp重载operator ++()会很方便.我会发现这个版本比默认的operator ++()版本更广泛使用.<
我正在尝试初始化类型的对象:
template<typename T>
struct thing : std::array<std::array<T, 2>, 2>
{
};
thing<int> t1 {{ {1,2}, {3,4} }};
Run Code Online (Sandbox Code Playgroud)
我明白了:
error: no matching function for call to ‘thing<int>::thing(<brace-enclosed initializer list>)’
thing<int> t1 {{{1,2},{3,4}}};
Run Code Online (Sandbox Code Playgroud)
同上
thing<int> t0{{ 1, 2, 3, 4 }};
Run Code Online (Sandbox Code Playgroud)
和其他几件事.
一个补丁被发布到gcc,它提供了一个叫做向量订阅g ++的东西(gcc已经有了它).
如果a
是一个数组并且i
是一个int则i[a]
是合法的并且等于a[i]
.
double a[]{0.0, 1.0, 2.0, 3.0}; // C++11 style but would work in C++98 style too.
assert(a[2] == 2.0);
assert(2[a] == 2.0);
Run Code Online (Sandbox Code Playgroud)
那么,这是合法的标准C/C++还是gcc扩展?
实际上,谷歌显示MS Developer Studio也有这个.我查看了C++标准并没有看到它.
我使用 pyspark 的方法是始终在 jupyter 中运行下面的代码。这种方法总是必要的吗?
import findspark
findspark.init('/opt/spark2.4')
import pyspark
sc = pyspark.SparkContext()
Run Code Online (Sandbox Code Playgroud) 我有一个程序,主要由Fortran 77和一个C++包装器组成,可以读写数据库.应用程序的两个部分通过使用一个功能共享数据,如果您使用名为Fortran公共块的全局C/C++结构.我很确定这种对C++/Fortran集成的别名方法1)适用于许多编译器套件,2)是*not8标准.我尝试维护我的代码,以便尽可能多地使用标准组件.此外,这种集成已被证明是脆弱的.
在utd.h中:
/*************************************************************
* This struct must follow the common block points.
* See the Fortran include file points.i
*************************************************************/
typedef struct ALIGN points
{
double point[3][MAX_PTS];
double edge[3][MAX_PTS];
double edgenorm[3][MAX_PTS];
double edgerho[MAX_PTS];
int nfacets[MAX_PTS];
double facet1[3][MAX_PTS];
double facet2[3][MAX_PTS];
double gaussk[MAX_PTS];
int sbstin[MAX_PTS];
int coatin[MAX_PTS];
int sbstout[MAX_PTS];
int coatout[MAX_PTS];
int ncorners[MAX_PTS];
double cnrpoint[3][MAX_CNRS][MAX_PTS];
int ncnredgs[MAX_CNRS][MAX_PTS];
double cnredge[3][MAX_CNREDS][MAX_CNRS][MAX_PTS];
int cnrsbst[MAX_CNREDS][MAX_CNRS][MAX_PTS];
int cnrcoat[MAX_CNREDS][MAX_CNRS][MAX_PTS];
int npoints;
} POINTS;
extern POINTS points_;
Run Code Online (Sandbox Code Playgroud)
在utd.cpp中:
POINTS points_;
Run Code Online (Sandbox Code Playgroud)
在points.i:
! maxpnt - maximum number of points …
Run Code Online (Sandbox Code Playgroud) c++ ×7
c++11 ×4
g++ ×2
algorithm ×1
c++-chrono ×1
fortran ×1
gcc ×1
gfortran ×1
graphics ×1
iota ×1
pimpl-idiom ×1
pyspark ×1
python ×1
unique-ptr ×1
visual-c++ ×1