他的场景 不用异常处理错误,还是快的。虽然这些年来异常已经进化了快了一些
注意你手写的guard类 构造函数不能失败,否则构造失败不析构就泄漏了
省流,fuck std::regex
#include <iostream>
#include <regex>
int main() {
std::string text = "Everyone loves Lucy.";
std::regex pattern(R"(.*+s}}@w)");
// Perform regex search
std::smatch match;
bool found = std::regex_search(text, match, pattern);
std::cout << "Regex search result: "
<< (found ? "Match found" : "No match") << std::endl;
return 0;
}
这段代码运行七分钟
抽象type 一个tag 重载 帮助function ref匹配constexpr函数
省流,boost::synchronized_value
folly也有synchronizedwith<T>
感觉这个周刊写的越多越发现重复。。评论区不知道的说一下,不行就folly组件挨个介绍
虽然和c++没啥关系,分享只是感叹AI太强了,程序员真的有点可有可无了
省流 池化加速助力 解析加快 局部性功劳
他讲的不是CPU那个pipeline,也不是任务调度那个pipeline,讲的是这个比玩意
template < typename InT, typename InE, typename Function >
requiresstd::invocable< Function, std::expected< InT, InE > >
&& is_expected< typenamestd::invoke_result_t< Function, std::expected< InT, InE > > >
constexprautooperator | ( std::expected< InT, InE > && ex, Function && f ) -> typenamestd::invoke_result_t< Function, std::expected< InT, InE > >
{
returnstd::invoke( std::forward< Function >( f ), /***/std::forward< std::expected< InT, InE > >( ex ) );
}
....
// ----------------------------------------------------------------------------------------------------------------
// Here we create our CUSTOM PIPE
auto res = PayloadOrError { Payload { "Start string ", 42 } } | Payload_Proc_1 | Payload_Proc_2 | Payload_Proc_3 ;
// ----------------------------------------------------------------------------------------------------------------
就是类似range的pipe语法传播
如何评价,光顾着耍帅了有点
继续介绍坑点
resize会初始化0, size == capacity
reserve不会 size == 0
但没有resize_with_overwrite这种跳过填0的操作,只有string有
resize reserve非常容易用错
struct Element {
size_t width; // original non-scaled width
....
};
// You are using smart component system that uses
// IDs to refer to elements.
using ElementID = uint64_t;
// Positions in OpenGL/DirectX/Vulkan worlds are floats
struct Offset {
float x;
float y;
};
size_t get_width(ElementID);
float screen_scale();
void move_by(ElementID, Offset);
void on_unchecked(ElementID el) {
auto w = get_width(el);
move_by(el, Offset {
-w * screen_scale() * 0.3f,
0.0f
});
}
这个-w必有问题,另外编译选项查不出来
#pragma pack(1)
struct Record {
long value;
int data;
char status;
};
int main() {
Record r { 42, 42, 42};
static_assert(sizeof(r) == sizeof(int) + sizeof(char) + sizeof(long));
std::cout <<
std::format("{} {} {}", r.data, r.status, r.value); // 42 - '*'
}
看这没问题?
int main() {
Record records[] = { { 42, 42, 42}, { 42, 42, 42} };
static_assert(sizeof(records) ==
2 * ( sizeof(int) + sizeof(char) + sizeof(long) ));
for (const auto& r: records) {
std::cout << std::format("{} {} {}", r.data, r.status, r.value); // 42 - '*'
}
}
改成两个就会炸
问题来自赋值隐式创建int 但实际上不是int,是pack bit
怎么解决?复制一份
int main() {
Record records[] = { { 42, 42, 42}, { 42, 42, 42} };
for (constauto& r: records) {
// C++23 has wonderful auto() for this purpose
std::cout << std::format("{} {} {}",
auto(r.data), auto(r.status), auto(r.value));
// In C++20,
auto data = r.data; auto status = r.status; auto value = r.value;
std::cout << std::format("{} {} {}", data, status, value);
// Or completely ugly and unstable to type changes
std::cout << std::format("{} {} {}", static_cast<int>(r.data),
static_cast<char>(r.status),
static_cast<long>(r.value>));
}
}
但实际上编译器应该阻止这种行为
后面还有coroutine的问题,特长。我准备拆开单独写一下
set (MY_CXX_FLAGS
"-Wall \
-Wextra \
-Werror \
-Wsuggest-override \
-Wno-unknown-warning-option \
-Wno-array-bounds \
-pedantic-errors" )
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_FLAGS}")