§14.10.3由约束部分排序[temp.constr.order]的N4553指定对的概念和逻辑运算符形成约束表达式应部分有序和用于选择在超载的情况下,最好可行函数。但这是否也适用于使用逻辑运算符的折叠表达式的约束表达式?
例如,gcc在这里给出一个不明确的重载错误是否正确,或者代码是否有效,打印“c”?
template <class T> concept bool A = std::is_move_constructible<T>::value;
template <class T> concept bool B = std::is_copy_constructible<T>::value;
template <class T> concept bool C = A<T> && B<T>;
template <class... _tx>
requires (A<_tx> && ...)
void g(_tx... tx) {
std::cout << "a\n";
}
template <class... _tx>
requires (C<_tx> && ...)
void g(_tx... tx) {
std::cout << "c\n";
}
f(3, 2.0)
Run Code Online (Sandbox Code Playgroud) 假设我定义了以下 gRPC 服务:
service Library {
rpc Search(SearchBookRequest) returns (stream SearchBookResponse) {}
}
message SearchBookRequest {
string term = 1;
int32 max_results = 2;
}
message SearchBookResponse {
int32 book_id = 1;
}
Run Code Online (Sandbox Code Playgroud)
它将搜索结果流式传输回指定的最大值。当通过 gRPC 的 Go API 与服务交互时,我可以做这样的事情吗?
for i:=0; i<maxResults; i++ {
search_result, err := stream.Recv()
if err == io.EOF {
// Note: If `maxResults` are returned this will never be reached.
break
}
if err != nil {
log.Fatalf("search error: %v", err)
}
fmt.Printf("Book-ID: %d\n", search_result.BookId)
} …Run Code Online (Sandbox Code Playgroud) 我知道你不能std::string从std::ostringstream没有复制中提取一个(从常量内存创建输入流).
但是有可能得到一个std::string_view吗?
如果我接受这个代码
#include <cmath>
void compute_sqrt(const double* x, double* y, int n) {
int i;
#pragma omp simd linear(i)
for (i=0; i<n; ++i) {
y[i] = std::sqrt(x[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
并使用 进行编译g++ -S -c -O3 -fopenmp-simd -march=cascadelake,然后我在循环中得到这样的指令(编译器-资源管理器)
...
vsqrtsd %xmm0, %xmm0, %xmm0
...
Run Code Online (Sandbox Code Playgroud)
XMM 是 128 位寄存器,但 Cascadelake 支持 avx-512。有没有办法让 gcc 使用 256 (YMM) 或 512 位 (ZMM) 寄存器?
相比之下,ICC 默认使用 256 个寄存器进行 Cascadelake:使用icc -c -S -O3 -march=cascadelake -qopenmp-simdProduces 进行编译 ( compiler-explorer )
...
vsqrtpd 32(%rdi,%r9,8), …Run Code Online (Sandbox Code Playgroud) 我正在查看 clang 模块的驱动程序测试用例:https : //github.com/llvm-mirror/clang/blob/master/test/Driver/modules.cpp
它包括生成 .pcm.o 文件的步骤。我想知道它们是干什么用的。
给定一个 c++20 模块
// a-m.cc
module;
#include <iostream>
export module a;
export void do_a() { std::cout << "A\n"; }
Run Code Online (Sandbox Code Playgroud)
您可以使用编译它
clang++ -std=c++20 -x c++-module --precompile a-m.cc -o a.pcm
Run Code Online (Sandbox Code Playgroud)
它生成预编译的模块文件a.pcm。
但是也有将 .pcm 文件编译为 .o 文件的步骤。
从驱动程序测试:
clang++ -std=c++20 a.pcm -S -o a.pcm.o
Run Code Online (Sandbox Code Playgroud)
如何使用 .pcm.o 文件?
如果我写一个主程序
// main.cc
import a;
int main() {
do_a();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译
clang++ -std=c++20 -c main.cc -fmodule-file=a=a.pcm
Run Code Online (Sandbox Code Playgroud)
然后尝试与 .pcm.o 链接,我得到
clang++ main.o …Run Code Online (Sandbox Code Playgroud) 例如,这段代码有效吗?
template <class T>
struct A {
void f()
requires std::is_same_v<T, int>
{
}
void f(int)
requires !std::is_same_v<T, int>
{
}
};
int main() {
auto fptr = &A<int>::f;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它不会用gcc 编译,但它似乎应该对我有用.
下面的代码中,成员的初始化b合法吗?
class B {
public:
explicit B(int) {}
};
struct A {
B b;
};
class C {
public:
C() : a{.b{33}} {}
A a;
};
Run Code Online (Sandbox Code Playgroud)
使用最新版本的 gcc 编译会出现此错误(wandbox)
prog.cc: In constructor 'C::C()':
prog.cc:12:11: error: converting to 'B' from initializer list would use explicit constructor 'B::B(int)'
12 | C() : a{.b{33}} {}
| ^~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
但是最新版本的 clang 可以很好地编译代码(wandbox)
哪个编译器是正确的?