我有以下代码:
#include <print>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::println("{}", v);
}
Run Code Online (Sandbox Code Playgroud)
在这产生的众多错误中,有(clang++ -std=c++23 -stdlib=libc++,https://godbolt.org/z/3z9Tseh37):
[...]/format_arg_store.h:167:17: error: static assertion failed due to [...]
167 | static_assert(__arg != __arg_t::__none, "the supplied type is not formattable");
| ^~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
这让我很困惑,因为根据cppreference C++23 编译器支持页面,libc++ 支持std::println并实现P2286: Formatting Ranges。
我做错了什么还是这是标准库错误?
这是一些 ghci
> :t (<*>)
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
> :t allEqual
allEqual :: Eq a => [a] -> [a] -> Bool
> :t allEqual <*> reverse
allEqual <*> reverse :: Eq a => [a] -> Bool
> :t reverse
reverse :: [a] -> [a]
Run Code Online (Sandbox Code Playgroud)
我正在尝试弄清楚 中应用程序的实例到底是什么allEqual <*> reverse。
我试图推理
f (a -> b) :: [a] -> [a] -> Bool
f a :: [a] -> [a]
f …Run Code Online (Sandbox Code Playgroud) S_1004_DKDL220006264-1A_HLGLFDSX3_L4_cleaned_1_fastqc.html
S_1004_DKDL220006264-1A_HLGLFDSX3_L4_cleaned_1_fastqc.zip
S_1004_DKDL220006264-1A_HLGLFDSX3_L4_cleaned_2_fastqc.html
S_1004_DKDL220006264-1A_HLGLFDSX3_L4_cleaned_2_fastqc.zip
S_1006_DKDL220006298-1A_HKFTLDSX3_L1_cleaned_1_fastqc.html
S_1006_DKDL220006298-1A_HKFTLDSX3_L1_cleaned_1_fastqc.zip
S_1006_DKDL220006298-1A_HKFTLDSX3_L1_cleaned_2_fastqc.html
Run Code Online (Sandbox Code Playgroud)
上面是文件夹中文件的名称。我想删除_从右数第二个到_左数第二个之间的内容。这样输出看起来像
S_1004__1_fastqc.html
S_1004__1_fastqc.zip
S_1004__2_fastqc.html
S_1004__2_fastqc.zip
S_1006__1_fastqc.html
S_1006__1_fastqc.zip
S_1006__2_fastqc.html
Run Code Online (Sandbox Code Playgroud)
我该如何使用 bash 来做到这一点?
我尝试了以下代码:
for file in *.html *.zip; do
new_name=$(echo "$file" | sed 's/_[^_]*_/_/')
mv "$file" "$new_name"
done
Run Code Online (Sandbox Code Playgroud)
但它没有按照我想要的方式工作。
我真的很喜欢vim的录音功能,但有时我需要“永久”录音。我不想每次都定义完全相同的录音。相反,我正在寻找一种解决方案,例如“将录音(!)保存到.vimrc文件中,以便每次打开 vim 时都会加载它”。类似的事情。是否可以?
考虑到可以创建这样的匿名结构:
#include <iostream>
struct {
int a;
int b;
} my_anonymous_struct = { 2,3 };
int main() {
std::cout << my_anonymous_struct.a << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,是什么原因导致错误出现呢?
#include <iostream>
struct file {
int min;
int max;
};
auto read_historic_file_dates(file F) -> struct { int min; int max; } {
return { F.min, F.max };
}
int main() {
file F = { 1, 4 };
auto [min_date, max_date] = read_historic_file_dates(F);
}
Run Code Online (Sandbox Code Playgroud)
错误:
<source>:8:42: error: declaration of anonymous struct must be a definition …Run Code Online (Sandbox Code Playgroud) 我经常发现自己在 if-else 链的所有分支的末尾重复一些代码:
例子:
if (cond1) {
// [...] code 1
// repeated code
} else if (cond2) {
// [...] code 2
// repeated code
} else if (cond3) {
// [...] code 3
// repeated code
}
Run Code Online (Sandbox Code Playgroud)
遵循DRY 原则的最佳方法是什么?
我想到了以下几点:
finally我希望可以在 if-else 链之后使用一个类似于异常的关键字。仅当前面的条件之一为真时,它才会执行代码:if (cond1) {
// [...] code 1
} else if (cond2) {
// [...] code 2
} else if (cond3) {
// [...] code 3
} …Run Code Online (Sandbox Code Playgroud) 我已在 Windows 10 系统上安装了 KinectV2 SDK,并在 SDK 浏览器中成功测试了它。
我尝试运行 Pykinect2 库中的一些代码,但导入时出现问题:
from pykinect2 import PyKinectV2
Run Code Online (Sandbox Code Playgroud)
错误:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[2], line 1
----> 1 from pykinect2 import PyKinectV2
2 from pykinect2.PyKinectV2 import *
File ~\Anaconda3\envs\kinect-env\lib\site-packages\pykinect2\PyKinectV2.py:2216
2131 ################################################################
2132 ## code template for ICoordinateMapper implementation
2133 ##class ICoordinateMapper_Impl(object):
(...)
2200 ## #return colorPoint
2201 ##
2203 tagSTATSTG._fields_ = [
2204 ('pwcsName', WSTRING),
2205 ('type', c_ulong),
(...)
2214 ('reserved', c_ulong),
2215 ]
-> 2216 assert sizeof(tagSTATSTG) == …Run Code Online (Sandbox Code Playgroud) 所以我有两个变体(我缩短了它们,它们有更多类型):
std::variant<int *, double *> PtrVariant;
std::variant<int, double> ValueVariant;
Run Code Online (Sandbox Code Playgroud)
我想在它们之间复制价值。
这不起作用:
ValueVariant = *PtrVariant;
Run Code Online (Sandbox Code Playgroud)
这有效:
if (std::holds_alternative<int>(ValueVariant))
ValueVariant = *std::get<int *>(PtrVariant);
else if (std::holds_alternative<double>(ValueVariant))
ValueVariant = *std::get<double *>(PtrVariant);
Run Code Online (Sandbox Code Playgroud)
有没有办法在它们之间复制值而不检查变体持有什么类型?
我试图在我的 Python 项目中使用 tesserocr,但是当我尝试导入它时,我遇到[No module named 'tesserocr']了 ImportError。该错误消息指出缺少与 Tesseract 库相关的符号。这是完整的错误消息:
ImportError: dlopen(/Volumes/WorkSpace/Backend/Reveratest/revera_api/venv/lib/python3.8/site-packages/tesserocr.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '__ZN9tesseract11TessBaseAPID1Ev'Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的:
使用brew安装了tesseract:brew install tesseract
在虚拟环境中通过 pip 安装 tesserocr:pip install tesserocr
确认 tesseract 命令行正常工作。我在 macOS M1 上运行它,我的 Python 版本是 3.8。
如何解决此问题以便我可以在我的项目中使用 tesserocr?是否有我可能缺少的特定路径或配置?
任何有关可能导致此错误的原因的帮助或指示将不胜感激!
#include <iostream>
//option 1
struct Obj
{
auto f(int&& x) { printf("&&\n"); }
auto f(int const& x) { printf("const&\n"); }
auto g() const { return int{}; }
const auto h() const { return int{}; }
};
//option 2
struct Obj2
{
auto f(Obj&& x) { printf("&&\n"); }
auto f(Obj const& x) { printf("const&\n"); }
auto g() const { return Obj{}; }
const auto h() const { return Obj{}; }
};
int main()
{
{
int x;
Obj obj;
obj.f(obj.g()); // …Run Code Online (Sandbox Code Playgroud)