我想弄清楚以下问题.
假设我在C++中有以下容器:
std::set<std::pair<int, int> > my_container;
Run Code Online (Sandbox Code Playgroud)
这组(字典)被相对于所述顺序排序<上std::pair<int, int>,这是字典顺序.我的任务是找到第一个坐标等于,比如说的任何元素,并将迭代器返回给它.显然,我不想使用,因为我需要在对数时间内解决这个问题.my_containerxfind_if
我很感激有关如何做到这一点的任何建议
我一直在尝试安装miniconda在 Alpine linux docker 映像上。我失败的最小“工作”示例可以用 Docker 重现,如下所示:
docker run --rm -it alpine sh
/ # apk update && apk add ca-certificates wget && update-ca-certificates
/ # wget https://repo.continuum.io/miniconda/Miniconda3-4.3.27-Linux-x86_64.sh -O ~/miniconda.sh
/ # sh miniconda.sh -b
PREFIX=/root/miniconda3
installing: python-3.6.2-h02fb82a_12 ...
/root/miniconda.sh: line 361: /root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python: not found
Run Code Online (Sandbox Code Playgroud)
但是,它查找的文件在那里:
/ # ls /root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python
/root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python
Run Code Online (Sandbox Code Playgroud)
我将不胜感激对此错误的一些见解。我不知道接下来要尝试什么
我正在尝试编写一个程序(对于给定的自然n,不超过50):
2n写出正确的括号的所有可能组合,这意味着在输出的每一行都有一系列具有这些属性的括号:
n开放,n封闭的括号我在Java中完成了几乎完全相同的代码并且它完美地工作,但不知何故以下代码中断:
MAX = 100;
arr = [];
for i in range(0, MAX):
arr.append(' ');
def write(n, pos, op, cl):
if (cl == n):
for i in range(0, MAX):
if arr[i] != ' ':
print(arr[i]);
else:
break;
print("\n");
else:
if (op > cl):
arr[pos] = ')';
write(n, pos+1, op, cl+1);
if (op < n):
arr[pos] = '(';
write(n, pos+1, op+1, cl);
n = raw_input();
write(n, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)
这个想法很基本,但是当我试图运行它时,我得到一个错误,说明在某些时候声明
arr[pos] …Run Code Online (Sandbox Code Playgroud) 我偶然发现了以下问题。说我有一个递归函数,比如
run :: [Int] -> [Int]
run [] = []
run (x:xs) = 1:x:run xs
Run Code Online (Sandbox Code Playgroud)
重要的是,它head $ run <whatever>始终是1。这意味着以下将产生输出1:
head $ run [error "shouldnt get here"]
Run Code Online (Sandbox Code Playgroud)
这证明 Haskell 在不需要的情况下不会评估参数——显然,因为这是 Haskell 最著名的特性之一。但是,如果我将结果用作参数,例如:
let out = run (cycle out) in head out
Run Code Online (Sandbox Code Playgroud)
我收到运行时错误<<loop>>。
怎么来的?
我正在使用runghc 8.4.2. 这是一个错误还是我在这里遗漏了什么?
我需要一些类型特征:
template<typename T> struct foo {};
template<>
struct foo<char> { static constexpr char c = 'c' };
Run Code Online (Sandbox Code Playgroud)
如果我需要c该类型的字符,这可以完美地工作char,但在以下情况下不是这样:
printf("%c", foo<const char>::c);
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方式来做到这一点,而不是指定两个模板char,并const char以同样的方式?
假设我有以下列表实现:
list=^listelement
listelement=record
w:integer;
next:list;
end;
Run Code Online (Sandbox Code Playgroud)
列表表示十进制写的大数(列表1 - > 2 - > 3表示数字123).
我想要做的是将这样的数字转换为二进制表示.因此,最直接的方法是将数字除以2
问题是我很难用2算法实现除法.我理解基本的算法,例如这个 https://www.mathsisfun.com/long_division.html,但我想不出一种方法可以将其转换为代码
我将不胜感激
我想我的整个问题在标题中都有很好的描述。我正在尝试创建一个可变参数类模板(在 C++11、C++14 或 C++1z 中)。
template<typename ...Types> struct MyVariadicTemplate {};
Run Code Online (Sandbox Code Playgroud)
并确保任何实例化中的类型列表MyVariadicTemplate都是单射的,例如,如果我调用以下代码段:
MyVariadicTemplate<int, double, int> x;
Run Code Online (Sandbox Code Playgroud)
它不会编译(我很乐意以某种方式使用static_assert)。
我会很感激的提示。
我正在尝试使用C++11模板的魔力来实现以下目标:
假设我有这样的类型:
using my_types = std::tuple<char, int, float>;
Run Code Online (Sandbox Code Playgroud)
有了这个,我想得到一个指向两者const而不是值的指针元组,即:
std::tuple<char *, int *, float *, const char *, const int *, const float *>;
Run Code Online (Sandbox Code Playgroud)
我现在的解决方案:
template<typename T>
struct include_const {};
template<typename... Types>
struct include_const<std::tuple<Types...>> {
using type = std::tuple<Types..., typename std::add_const<Types>::type...>;
};
Run Code Online (Sandbox Code Playgroud)
这给了std::tuple<types, const types>.要获得指针,我可以使用:
template<typename T>
struct add_ptr {};
template<typename... Types>
struct add_ptr<std::tuple<Types...>> {
using type = std::tuple<typename std::add_pointer<Types>::type...>;
};
Run Code Online (Sandbox Code Playgroud)
这工作,但我想这得到多一点的一般:我想有一个template<trait, Types...> add_ptr,让我指针都Types...和trait<Types>::type...,这样使用可能是以下几点: …
我正在尝试学习操作系统的工作方式。这是我要解决的一个容易的任务:编写一个简单的引导程序,提示用户输入他的名字并打印欢迎消息,例如“ hello,>> name <<”-之后,它什么也不做。
如果minix 3与qemu此相关,我正在与一起运行。我只是将asm文件dd及其前512个字节编译为/dev/c0d0(的虚拟硬盘minix)。
我可以打印消息并打印用户输入的内容。但是,此后我没有设法打印用户名。
这是我的汇编代码:
[bits 16]
[org 0x7c00]
mov si, HelloString
call print_string
mov di, name
call read_name
mov si, name
call print_string
read_name:
read_char:
mov ah, 0h ; read character from keyboard
mov [di], ah ; save it in the buffer
inc di ; next char
int 0x16 ; store it in AL
cmp ah, 0x0d ; check for enter
je stop_reading
mov …Run Code Online (Sandbox Code Playgroud) 最近我一直在使用OpenCASCADE(准确地说是PythonOCC)进行一些CAD操作,包括网格形状,并偶然发现了这个类: BRepMesh_IncrementalMesh.
我没有找到关于什么theLinDeflection和theAngDeflection参数含义的任何暗示- 并且想要了解更多关于此的信息.
我将不胜感激任何关于这一主题的阅读材料/提示/解释.
我想知道我想要实现的目标是否可行 C++
假设我有一个模板
template<typename T>
struct Foo {
static void foo();
};
Run Code Online (Sandbox Code Playgroud)
和非constexpr char c.现在,我想创建一个实例Foo并使用它做一些事情,具体取决于我的角色的值:
if (c == 'i')
Foo<int>::foo();
else if (c == 'f')
Foo<float>::foo();
....
Run Code Online (Sandbox Code Playgroud)
有更优雅的方式吗?我想的可能是写一个char trait,像这样:
template<char c>
struct char_trait {};
template<>
struct char_trait<'i'> {
using type = int;
};
Run Code Online (Sandbox Code Playgroud)
但由于c非constexpr,这没有多大意义.
我会很感激一些提示
我正在尝试解决以下问题:
假设我正在编写一个类,它有一个myMethod修改两者的方法*this和传递的参数:
class MyClass {
//some code here
void myMethod(MyClass& other) {
//modify *this and other
}
};
Run Code Online (Sandbox Code Playgroud)
问题是,当调用以下部分时,我希望该方法不执行任何操作:
MyClass x;
x.myMethod(x);
Run Code Online (Sandbox Code Playgroud)
检查相等是不够的,因为我希望能够为两个相同的对象调用它.
例如,以一种更为实际的方式,假设它MyClass是类似的std::set并且myMethod合并两个集合,清空other.可以合并两个相同的集合,但我显然不能清空并同时填充一个集合.
我该如何检查?任何建议将被认真考虑.
c++ ×6
templates ×4
algorithm ×2
c++11 ×2
alpine-linux ×1
anaconda ×1
assembly ×1
bootloader ×1
class ×1
containers ×1
docker ×1
haskell ×1
largenumber ×1
mesh ×1
methods ×1
minix ×1
opencascade ×1
osdev ×1
pascal ×1
python ×1
recursion ×1
stl ×1
traits ×1
x86 ×1