为什么constexpr函数在编译时没有被评估,而是在main函数的return语句中运行时?
它试过了
template<int x>
constexpr int fac() {
return fac<x - 1>() * x;
}
template<>
constexpr int fac<1>() {
return 1;
}
int main() {
const int x = fac<3>();
return x;
}
Run Code Online (Sandbox Code Playgroud)
结果是
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 6
mov eax, 6
pop rbp
ret
Run Code Online (Sandbox Code Playgroud)
与gcc 8.2.但是当我在return语句中调用该函数时
template<int x>
constexpr int fac() {
return fac<x - 1>() * x;
}
template<>
constexpr int fac<1>() {
return 1;
}
int main() {
return fac<3>(); …Run Code Online (Sandbox Code Playgroud) 我在一个 C++11 项目中工作,我尝试了以下代码
#include <atomic>
struct A {
std::atomic_int idx = 1;
};
int main() {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误
error: use of deleted function 'std::__atomic_base<_IntTp>::__atomic_base(const std::__atomic_base<_IntTp>&) [with _ITp = int]'
std::atomic_int idx = 1;
^
Run Code Online (Sandbox Code Playgroud)
C++14 也有同样的结果。当我切换到 C++17 时它可以工作:wandbox
我检查了 cppreference 的差异:
但是 C++14 和 C++17 之间没有区别。为什么它适用于 C++17 而不适用于 C++14?
我正在创建一个具有类似问题的图像,如以下 docker 项目:
FROM alpine:3.9.3
COPY ./env.sh /env.sh
RUN source /env.sh
CMD env
Run Code Online (Sandbox Code Playgroud)
TEST=test123
Run Code Online (Sandbox Code Playgroud)
我用
docker build -t sandbox .
Run Code Online (Sandbox Code Playgroud)
并运行它
docker run --rm sandbox
Run Code Online (Sandbox Code Playgroud)
输出是
HOSTNAME=72405c43801b
SHLVL=1
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
Run Code Online (Sandbox Code Playgroud)
我的环境变量丢失了。
在实际项目中,我必须为 IBM DB2 客户端的安装提供更长的复杂脚本,该脚本还设置了环境变量。如何在不阅读整个安装过程并ENV在 dockerfile 中设置所有变量的情况下实现它?
编辑:在实际项目中,该文件env.sh是作为安装过程的一部分创建的,并且不能从容器外部使用。环境变量的设置取决于它在其上执行的系统。如果我在主机上运行它,它会在来宾中设置错误的变量。
真实脚本的一部分是
if [ -f ${INST_DIR?}/tools/clpplus.jar ]; then
AddRemoveString CLASSPATH ${INST_DIR?}/tools/clpplus.jar a
fi
if [ -f ${INST_DIR?}/tools/antlr-3.2.jar ]; then
AddRemoveString CLASSPATH ${INST_DIR?}/tools/antlr-3.2.jar a
fi
if [ -f ${INST_DIR?}/tools/jline-0.9.93.jar ]; then
AddRemoveString CLASSPATH ${INST_DIR?}/tools/jline-0.9.93.jar a
fi
if …Run Code Online (Sandbox Code Playgroud) 在我的 Dockerfile 中,我需要使用命令替换来添加一些环境变量。我想设置
ENV PYTHONPATH /usr/local/$(python3 -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
Run Code Online (Sandbox Code Playgroud)
但它不起作用。结果是
foo@bar:~$ echo $PYTHONPATH
/usr/local/$(python3 -c from distutils import sysconfig; print(sysconfig.get_python_lib()))
Run Code Online (Sandbox Code Playgroud)
怎么了?
我想将逻辑从组件转移到服务.但我发现我无法在服务中获得routeParams.
我的组件看起来像
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { MyService } from '../services/my.service';
@Component({
moduleId: module.id,
templateUrl: 'my.component.html',
styleUrls: ['my.component.css']
})
export class MyComponent implements OnInit {
constructor(private myService: MyService, private route: ActivatedRoute) {;}
public ngOnInit() {
this.route.params
.subscribe((params: Params) => {
debugger;
console.log(params);
});
this.myService.getParams()
.subscribe((params: Params) => {
debugger;
console.log('Return1:');
console.log(params);
}, (params: Params) => {
debugger;
console.log('Return2:');
console.log(params);
}, () => {
debugger;
console.log('Return3:');
});
}
};
Run Code Online (Sandbox Code Playgroud)
我的服务看起来像 …
我在我的Raspberry Pi 2上安装了docker,想要拉一些图像.但是当我试着拉着时docker pull nginx,我明白了Could not reach any registry endpoint.我的网络连接正常,甚至docker search nginx回显所有图像.我从raspbian存储库安装了docker,sudo apt-get install docker.io因此它是旧版本.我无法安装新版本.docker版本是1.3.3.
也请问:https: //raspberrypi.stackexchange.com/questions/51029/docker-on-raspberry-pi-2-could-not-reach-any-registry-endpoint
我有一个组件 ( App),其中包含另一个组件 ( Comp)。App从数据库获取字符串内容并将其转发@Input()到Comp。该字符串内容可以包含 html 标签,例如
Some text before <a>Click</a> Some Text after
Run Code Online (Sandbox Code Playgroud)
在Comp此内容中应该呈现并且应该添加一些事件侦听器。因此,此内容是使用添加的[innerHtml]。因为需要在对标记的引用(click)中删除,并且应该添加事件侦听器。但我找不到引用该标签的方法,因为组件的 an 不包含.[innerHtml]aaddEventListeneraElementRefnativeElement
让这个笨蛋运行的最佳方法是什么? https://plnkr.co/edit/xVUu0LJ02YVnBO25Zr4j?p=preview
我已经将大量 .jpg 图像从我的 Google Drive 复制到 Google Colab 每个Google Colab:如何从我的谷歌驱动器读取数据?:
local_download_path = os.path.expanduser('~/data')
try:
os.makedirs(local_download_path)
except: pass
# 2. Auto-iterate using the query syntax
# https://developers.google.com/drive/v2/web/search-parameters
file_list = drive.ListFile(
{'q': "'1SooKSw8M4ACbznKjnNrYvJ5wxuqJ-YCk' in parents"}).GetList()
for f in file_list:
# 3. Create & download by id.
print('title: %s, id: %s' % (f['title'], f['id']))
fname = os.path.join(local_download_path, f['title'])
print('downloading to {}'.format(fname))
f_ = drive.CreateFile({'id': f['id']})
f_.GetContentFile(fname)
Run Code Online (Sandbox Code Playgroud)
这已完成,因此所有图像文件都应位于一个data文件夹中。我现在如何实际访问这些文件?我想遍历文件data夹中所有 .jpg 类型的文件。
我正在使用以下结构的程序:
#include <iostream>
#include <string>
void fun(const std::string &text, int a, int b) { // (1)
std::cout << text << a + b << std::endl;
}
template<typename ...Args>
void execute(void(*fun)(Args...), Args ...args) {
fun(args...);
}
void init(const std::string &text, int a, int b) {
execute(fun, text, a, b);
}
int main() {
init("Fun: ", 1, 2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误消息
.code.tio.cpp:14:2: error: no matching function for call to 'execute'
execute(fun, text, a, b);
^~~~~~~
.code.tio.cpp:9:6: note: candidate template ignored: deduced …Run Code Online (Sandbox Code Playgroud) c++ templates variadic-templates c++11 template-argument-deduction
是否可以检查位置路径?我是AngularJS的新手,我正在学习一本描述ngScenario的书.这个软件包已被弃用,我正在尝试将描述的测试更新为量角器.
例如
expect(browser().location().path()).toEqual('/books');
Run Code Online (Sandbox Code Playgroud)
变为:
expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/#/books');
Run Code Online (Sandbox Code Playgroud)
但我想避免http://localhost:8080/.
c++ ×3
angular ×2
docker ×2
dockerfile ×2
javascript ×2
angularjs ×1
automation ×1
c++11 ×1
c++14 ×1
c++17 ×1
clang ×1
constexpr ×1
gcc ×1
protractor ×1
python ×1
raspbian ×1
selenium ×1
stdatomic ×1
template-argument-deduction ×1
templates ×1
typescript ×1