我有这样的功能:
void loadData(std::function<void (std::string, std::string, std::string)> callback)
{
// data loading stuff
callback(body, subject, header);
}
Run Code Online (Sandbox Code Playgroud)
问题是我并不需要使用subject,并header在我的回调函数.现在我正在以这种方式处理它:
loadData([](std::string body, std::string, std::string){
std::cout << body;
})
Run Code Online (Sandbox Code Playgroud)
我想用它替换它
loadData([](std::string body){
std::cout << body;
})
Run Code Online (Sandbox Code Playgroud)
并自动传递给回调函数尽可能多的参数.我不想loadData为所有3个可能的参数计数手动重载函数.我也不想在调用站点上使用任何更复杂的lambda语法,因为我的库应该清楚,供其他人使用.这可能使用C++ STL和Boost吗?
我正在尝试编译此示例(保存为main.go当前工作目录):
package main
import (
"flag"
"log"
"runtime"
"github.com/nats-io/go-nats"
)
// rest of the code
Run Code Online (Sandbox Code Playgroud)
这有效:
$ go build ./
Run Code Online (Sandbox Code Playgroud)
但这不是:
$ go tool compile -o main.o main.go
main.go:8:2: can't find import: "github.com/nats-io/go-nats"
Run Code Online (Sandbox Code Playgroud)
上面的两个例子都是在具有相同环境变量的同一个终端上运行的,所以我不明白为什么第二个不起作用.我已尝试-D和-I各种目录的参数$GOPATH,$GOPATH/src等等,但没有成功.
我知道不使用go tool compile等等的最佳做法是什么,但我的目标是将我的go源添加到现有的C++ makefile项目中,并且使用go tool它将使其更加一致.
我想创建一个可以使用模板参数隐式转换为另一个类的类.这是我想要实现的MCE:
#include <iostream>
template <typename T>
class A {
T value;
public:
A(T value) {this->value = value;}
T getValue() const {return value;}
};
class B {
int value;
public:
B(int value) {this->value = value;}
operator A<int>() const {return A(value);}
};
template <typename T>
void F(A<T> a) {std::cout << a.getValue() << std::endl;}
void G(A<int> a) {std::cout << a.getValue() << std::endl;}
int main()
{
B b(42);
F(b); // Incorrect
F((A<int>)b); // Correct
G(b); // Also correct
}
Run Code Online (Sandbox Code Playgroud)
是否有可能使F(b)例如工作如果两个class A …
我在我的 Gitlab CI 构建阶段使用这个脚本(只显示相关部分):
cache:
key: "$CI_BUILD_REF"
paths:
- bin/
- build/
build:
image: <my_build_image>
stage: build
script:
- "make PLATFORM='x86_64-linux-gnu' BUILD='release' JOBS=8 all"
only:
- master
- tags
- merge-requests
artifacts:
untracked: true
paths:
- bin/x86_64-linux-gnu/release
Run Code Online (Sandbox Code Playgroud)
我想,如果我将添加bin和build迪尔斯到缓存中,make每次都不会重建整个项目(就像它在当地的行为),但似乎什么CI亚军重写我的srcDIR每一次,所以时间戳的文件正在也更新了,并make认为每个文件都更新了。我想将srcdir 包含在缓存中,但它包含在 repo 中,我不确定这是否正确。那么,使用以前构建的二进制文件重建 gitlab ci 项目的最佳方法是什么?