小编Vin*_*ent的帖子

在python中平滑曲线,边界没有错误?

考虑有两个numpy的阵列相关的下列曲线xy:

曲线

如何在python中正确平滑它并没有问题xmax?(如果我应用高斯滤波器,曲线最后会上升)

数据在这里(两列):http://lite4.framapad.org/p/xqhpGJpV5R

python math interpolation numpy scipy

3
推荐指数
2
解决办法
1684
查看次数

为什么std :: bitset :: reference :: operator~?

我正在阅读文档,std::bitset我想知道为什么std::bitset::reference明确定义,operator~因为我没有看到任何性能或设计原因.没有它,我认为它同样有效:

bool b = ~mybitset[i];
Run Code Online (Sandbox Code Playgroud)

因为引用将转换为bool,~操作符将应用于bool .

对此设计决定有何解释?

c++ standards std bitset

3
推荐指数
1
解决办法
60
查看次数

下溢或溢出的指针会发生什么?

我有一个类只是一个原始指针包装器.我想知道我是否可以申报:

  • operator++()
  • operator--()
  • operator++(int)
  • operator--(int)

作为noexcept.这些操作符可以抛出的唯一原因是因为原始指针会抛出.所以问题是:--在已经指针的0情况++下调用时会发生什么,以及在最大指针上调用时会发生什么?

c++ standards pointers exception c++11

3
推荐指数
1
解决办法
169
查看次数

当第一个<= last未满足时,C++标准对算法有何规定?

当条件first <= last未满足时,官方C++标准对算法的说法是什么,first并且last迭代器是否传递给其中一个标准算法?

我看到三种可能性:

  • 要求算法检查条件,以便在未填满时算法不执行任何操作
  • 算法需要抛出异常
  • 这是未定义的行为,所以......任何事情都可能发生

我很困惑,因为在算法描述中我没有看到requires关于first和的条款last.

编辑1:这是问题的简化.更精确的版本是" 通过连续应用last无法达到的算法会发生什么?firstoperator++

编辑2:我问这个问题,因为我正在实现一个专业化,std::reverse我想知道我是否应该检查这个条件,或者我是否可以允许函数在last无法访问时做一些完全错误的事情first

c++ algorithm undefined-behavior c++-standard-library language-lawyer

3
推荐指数
1
解决办法
79
查看次数

强制缩小转换警告

请考虑以下代码,说明一些缩小的转换:

template <class T>
class wrapper 
{   
    template <class> friend class wrapper;
    public:
        constexpr wrapper(T value)
        : _data(value)
        {}
        template <class U>
        constexpr wrapper(wrapper<U> other)
        : _data(other._data) 
        {}
        wrapper& operator=(T value)
        {_data = value; return *this;}
        template <class U>
        wrapper& operator=(wrapper<U> other)
        {_data = other._data; return *this;}
    private:
        T _data;
};

int main(int argc, char* argv[]) 
{
    wrapper<unsigned char> wrapper1 = 5U;
    wrapper<unsigned char> wrapper2{5U};
    wrapper<unsigned char> wrapper3(5U);
    wrapper<unsigned int> wrapper4 = 5U;
    wrapper<unsigned int> wrapper5{5U};
    wrapper<unsigned int> wrapper6(5U);
    wrapper<unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-warnings implicit-conversion narrowing c++14

3
推荐指数
1
解决办法
531
查看次数

auto,decltype(auto)和尾随返回类型

是否有区别:

template <class T>
constexpr decltype(auto) f(T&& x) -> decltype(std::get<0>(std::forward<T>(x)))
{
    return std::get<0>(std::forward<T>(x));
}
Run Code Online (Sandbox Code Playgroud)

和:

template <class T>
constexpr auto f(T&& x) -> decltype(std::get<0>(std::forward<T>(x)))
{
    return std::get<0>(std::forward<T>(x));
}
Run Code Online (Sandbox Code Playgroud)

如果是的话,它是什么,我应该使用哪一个来完美转发?

c++ decltype auto trailing-return-type c++14

3
推荐指数
1
解决办法
1004
查看次数

从模板类型而不是参数获取转发类型

考虑以下功能:

template <class T>
constexpr /* something */ f(T&& x) {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

并且假设我想根据传递给被调用函数的转发参数的类型来做sfinae myfunction.实现这一目标的一种方法是:

template <class T>
constexpr auto f(T&& x) -> decltype(myfunction(std::forward<T>(x))) {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

而不是这样做,有没有办法在模板级别执行此操作:

// This code won't compile
template <class T, class R = decltype(myfunction(std::forward<T>(x)))>
constexpr R f(T&& x) {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

除了我还没有访问权限,x所以这段代码不会编译.有没有办法只基于T(可能使用std::declval)来实现这一目标?

注意:这不是一个X/Y问题,它只是一个例子来说明这种情况发生的地方:我不知道如何在不访问变量的情况下进行转发SFINAE,因为对我而言,行为std::forward仍然有点神秘.

c++ template-meta-programming perfect-forwarding trailing-return-type c++14

3
推荐指数
1
解决办法
175
查看次数

仅使用有关类型而非对象的信息返回调用类型

请考虑以下代码:

template <class F, class... Args>
void function(F&& f, Args&&... args)
{
    using type1 = decltype(std::forward<F>(f)(std::forwards<Args>(args)...));
    using type2 = decltype(/*equivalent expression but only using types */);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在所有情况下使用type2相同的方法,type1但只使用decltype表达式中的类型,或者换句话说只使用FArgs而不是fargs

c++ decltype perfect-forwarding c++11 forwarding-reference

3
推荐指数
1
解决办法
166
查看次数

有没有办法刷新与程序相关的整个CPU缓存?

x86-64平台上,CLFLUSH汇编指令允许刷新对应于给定地址的缓存行.相反,冲洗与特定地址的缓存,会有一种通过使其充满了虚拟的内容,以刷新整个高速缓存(或者相关程序的缓存中执行,或整个高速缓存),例如(或任何我不会意识到的其他方法):

  • 仅使用标准C++ 17?
  • 如有必要,使用标准C++ 17和编译器内在函数?

以下函数的内容是什么:(无论编译器优化如何,该函数都应该工作)?

void flush_cache() 
{
    // Contents
}
Run Code Online (Sandbox Code Playgroud)

c++ memory optimization assembly cpu-cache

3
推荐指数
1
解决办法
4042
查看次数

C++ 2011:基于范围的循环展开?

我想知道C++编译器是否会像目前为"正常"循环一样展开基于范围的循环以最大化性能,或者在某些情况下基于范围的循环将比正常循环慢?

非常感谢你.

c++ compiler-construction loops c++11

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