Chao's Garden

C++ STL Algorithm 里的比较函数

这篇我想聊的是,类似 std::sort、std::priority_queue 或者 lower_bound/upper_bound 的定制比较函数。 template< class RandomIt, class Compare > void sort( RandomIt first, RandomIt last, Compare comp ); template< class ForwardIt, class T, class Compare > ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value, Compare comp ); template< class ForwardIt, class T, class Compare > ForwardIt upper_bound( ForwardIt first, ForwardIt last, const T& value, Compare comp ); template< class T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type> > class priority_queue; 在面试做题或者实际工作中,有时候我们遇到的类型 T 是一个复合类型,无法应用默认的比较函数;或者我们对于排序有自己的规则,这种情况就需要实现定制化的比较函数,通常通过仿函数(Functor)或者 Lambda 表达式实现。

Build docker image and run docker container on MacOS M1

Build docker image for macOS M1 docker buildx build --platform linux/arm64 --load -t rcore_lab . Explanation docker buildx build: This initiates the Docker Buildx build process. Docker Buildx is a CLI plugin that extends the functionality of Docker’s build command, allowing for advanced features like multi-platform builds, cache import/export, and more. --platform linux/arm64: This flag specifies the target platform for the build. In this case, it is set to linux/arm64, which means the Docker image will be built for the ARM64 architecture on a Linux operating system.

How evil a comma could be in Python

How bad a comma could be in Python? Though I have been using Python for a couple of years, mainly as a utility to help develop software, I am still surprised by Python from time to time. Sometimes is the Sytanx sugar making me realise how elegant a Python code could be, sometimes is the caveat annoying me. Here is the story, in the beginning, I had a code like the one below (for the demo purpose, I simplify the code here):