标签: standard-library

模拟 C++ 标准库

我正在对 C++ 中的一个类进行单元测试,一些公共方法调用私有方法。我知道约定是测试公共接口,但类的功能取决于这些私有方法如何依次调用其他类及其方法。这与公共接口类似,无论私有函数发生什么,它仍然符合 API。

我已经能够在大部分情况下模拟私有函数中调用的类来测试 API,但在少数情况下,我遇到了引用标准库的地方,但未能成功模拟它。模拟标准库类等有什么技巧吗?或者我应该跳过它们?

-- 另外,我无法更改源代码或使用模拟库。

c++ unit-testing mocking std standard-library

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

C 标准一致性 - 标识符

我正在寻找关于 C 标准(C99 和/或 C11)部分的一些说明,主要是关于identifiers的使用。
上下文是一个完整的 C99 标准库的实现,我希望它完全符合标准。

基本问题是:C 标准允许我在多大程度上声明标准中未列出的标识符/符号?

例如,让我们考虑isfinite来自math.h.
一个可能的实现可能是:

#define isinf( _x_ )                                                       \
    (                                                                      \
        ( sizeof( _x_ ) == sizeof( float  ) ) ? _c99_math_isinf_f( _x_ ) : \
        ( sizeof( _x_ ) == sizeof( double ) ) ? _c99_math_isinf_d( _x_ ) : \
                                                _c99_math_isinf_l( _x_ )   \
    )

int _c99_math_isinf_f( float x );
int _c99_math_isinf_d( double x );
int _c99_math_isinf_l( long double x );
Run Code Online (Sandbox Code Playgroud)

在这里,我需要声明显然不属于C …

c standards standards-compliance c99 standard-library

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

Clojure拉链功能

我需要通过组合给定seq的第一,第二等元素来构建seqs(vec vec).

经过快速搜索并查看备忘单.我还没有找到一个并完成自己的写作:

(defn zip 
  "From the sequence of sequences return a another sequence of sequenses
  where first result sequense consist of first elements of input sequences
  second element consist of second elements of input sequenses etc.

  Example:

  [[:a 0 \\a] [:b 1 \\b] [:c 2 \\c]] => ([:a :b :c] [0 1 2] [\\a \\b \\c])"
  [coll]
  (let [num-elems (count (first coll))
        inits (for [_ (range num-elems)] [])]
    (reduce (fn [cols elems] (map-indexed
                              (fn [idx coll] (conj …
Run Code Online (Sandbox Code Playgroud)

sequences clojure standard-library

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

如何将 std::vector 的某些元素移动到向量中的新索引?

我正在移植一些我编写的旧手工数组处理类,现在使用 std 库容器。我在移植时遇到问题的一种方法是我称之为“ChangeRecordOrder”的方法,因为没有更好的术语。我需要一个标准库替换。

它的定义是:

template <class T>
void ChangeRecordOrder( std::vector<T> IN OUT &inputVector, 
                        uint newInsertIndex, 
                        std::vector<uint> IN const &indexesToMoveToNewIndex );
Run Code Online (Sandbox Code Playgroud)

例如(伪代码):

MyVector<uint> = {0,10,20,30,40,50,60,70,80,90}
IndexesToMove = {2,4}
NewIndex = 6

After call to ChangeRecordOrder( MyVector, NewIndex, IndexesToMove ):

MyVector<uint> == {0,10,30,50,20,40,60,70,80,90}
Run Code Online (Sandbox Code Playgroud)

请注意,2 和 4(20 和 40)处的元素被移动到原始向量的索引 6(在 60 之前)。

当然,我想就地做这件事,而不是使用另一个临时向量。我也不介意在调用之前需要对 IndexesToMove 向量进行排序的要求。

我找不到为此的标准库算法。我之前在原始内存上工作的算法没有使用 c++ 移动语义。

谢谢!

c++ sorting algorithm standard-library

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

为什么有些 Python 标准库是用 .so 编写的,而其他大多数是用 .py 编写的?

大多数标准库是用 Python .py 文件编写的,但有些是在 Unix 上的 .so 文件和 Windows 上的 .pyd 文件中。例如 os 写在 os.py 中,而 pyexpat 写在 pyexpat.cpython-36m-darwin.so 中。这些 .so 库有什么特别之处?

python standard-library .so

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

PureScript 等价于 Haskell 的 &gt;&gt; 运算符

是否有与 Haskell>>运算符等效的 PureScript 标准库?

class Monad m where
...
(>>) :: m a -> m b -> m b
...
Run Code Online (Sandbox Code Playgroud)

显然,定义很简单,但如果有的话,我更愿意使用库版本。

monads standard-library purescript

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

Python标准模块中是否存在此函数的类似内容?

我正在寻找一个标准函数(运算符,装饰器),它等同于下面的手写函数:

def defaulted(func, defaultVal):
   try:
      result = func()
   except: 
      result = defaultVal

   return result
Run Code Online (Sandbox Code Playgroud)

谢谢!

python exception standard-library

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

Python标准库包/模块不在名为python的包中是否有原因?

因为它是在Java中完成的...这使得断言包/模块是否属于标准库的任务是微不足道的.我猜这只是一个惯例.有没有计划在未来改变这种情况?

提前致谢.

python standard-library package

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

我怎么能告诉默认包含Rust std lib的哪些模块?

例如

如果我想要stdin()我需要:

use std::io;
Run Code Online (Sandbox Code Playgroud)

如果我想x.cos(),其中x是,例如,f64:

use std::num::FloatMath
Run Code Online (Sandbox Code Playgroud)

不需要.

我磕磕绊绊地发现了这一点.是否有更正式的信息来源?

standard-library rust

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

使用std :: map和std :: list :: iterator

为什么这段代码不能编译?

#include <map>
#include <list>

int main()
{
    typedef std::list<int>::iterator Iter;

    std::map<Iter, Iter> m;

    std::list<int> ints;

    m[ints.begin()] = ints.begin();
}
Run Code Online (Sandbox Code Playgroud)

如果我改变std::liststd::vector,一切正常.

错误日志如下:

|| "==== Building Practical (release) ===="
|| main.cpp
In file included from C:\mingw32\i686-w64-mingw32\include\c++\bits\stl_tree.h|65| 0,
||                  from C:/mingw32/i686-w64-mingw32/include/c++/map:60,
||                  from ../src/main.cpp:1:
|| C:/mingw32/i686-w64-mingw32/include/c++/bits/stl_function.h: In instantiation of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::_List_iterator<int>]':
C:\mingw32\i686-w64-mingw32\include\c++\bits\stl_map.h|498 col 32| required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = …
Run Code Online (Sandbox Code Playgroud)

c++ iterator compiler-errors std standard-library

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