在程序中经常看见eval的用法,最初不太熟悉,故特意记录一下。
假设,set 11 22 33 44,如果打印第4个参数,则直接使用echo $4就可以,但是,
如果不知道有几个具体的参数时怎么办。
eval echo "\$$#"
相当于命令被执行两次,第一次语义替换,第二次才是真正打印命令。
目前工作上需要处理理解这个东西,故放在这里增强记忆。
The AT24C01C/AT24C02C is delivered with the EEPROM array set to logic ‘1’, resulting in FFh data in all locations.
这句话的意思是, 初始化EEPROM的值为 每一个寄存器 为 FF
大部分参考这个内容 i2c目前多集中于单片机内部的通信,用于连接微处理器与外围设备,是PHILIPS串行总线。一般i2c总线由SDA和SCL两条线构成,其中
这个命令是检测i2c设备.
本篇是第一篇接触如此高级议题的c++的文章,让我们来看一下c++的lambda的表达式。
lambda是一个新鲜事物(相比c98),其实到c++ 14这个东西也在不停的发展,还是有一些意思的,至于为什么引入lambda表达式,我目前也没有搞明白,如果后面有一个深入的理解,我再回来补充完善。
(浅显的理解就是,lambda用作为捕捉,就是以一种全新的方式用作简化表达的方式,新的语法。但是优势在哪里,目前不知道) c++给人的感觉就是不停的自我革命,前一版的限制,下一版出来一个特性突破上次的限制。
根据官方文档, 记录点自己的心得,简单的概念理解,可以看这篇文章。
一般的函数定义为:
ret_value function_name(parameter) option { function_body; }
而lambda表达式的形式为:
[ capture ] ( parameter ) option -> return_type { body; };
看到这个箭头,我就突然想起了Rust中,也有类似的用法。
捕捉在形式上利用”,”分割,当然也有一些默认的捕捉符。
[]不捕获任何变量[&]以引用的方式捕获外部作用域的所有变量[=]以赋值方式捕获外部作用域的所有变量[=, &foo]以赋值的方式捕获外部作用域所有变量,以引用方式捕获foo变量[bar]以赋值方式捕捉bar变量,不捕获其他变量[this]捕获当前类的this指针,让lambda表达式拥有和当前类成员同样的访问权限,可以修改类的成员变量,使用类的成员函数。如果已经使用了&或者=,就默认添加此选项。以下几点为特殊说明:
A lambda expression can use a variable without capturing it if the variable
1. is a non-local variable or has static or thread local storage duration (in which case the variable cannot be captured), or
2. is a reference that has been initialized with a constant expression.
A lambda expression can read the value of a variable without capturing it if the variable
1. has const non-volatile integral or enumeration type and has been initialized with a constant expression, or
2. is constexpr and has no mutable members.
符号“()”可以作为他的默认构造函数,看下面的例子:
// generic lambda, operator() is a template with two parameters
auto glambda = [](auto a, auto&& b) { return a < b; };
bool b = glambda(3, 3.14); // ok
返回值为auto类型的lambda值,可以被称为generic lambda,从这个简单的例子看的出来,这和模板(template)没有太多的区别。
一个综合的例子:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
std::vector<int> c = {1, 2, 3, 4, 5, 6, 7,8};
int x = 5;
c.erase(std::remove_if(c.begin(), c.end(), [x](int n) { return n < x;}), c.end());
std::cout << "c" << endl;
std::for_each(c.begin(), c.end(), [](int i){ std::cout << i << " "; });
}
何谓c++的基础算法? 就是那些基本的算法,比如 reverse, is_sorted, is_unique等。这些usage在一些场景下使用的比较多。
std::is_sorted 用来判断一个容器是否为一个已排序的容器,比如[1,2.3],然后有一个不满足就会return false;
vector<int> ans = [1,2,3];
if(std::is_sorted(std::begin(res), std::end(res)))
return true;
具体的实现可能为:
template<class ForwardIt>
bool is_sorted(ForwardIt first, ForwardIt last)
{
return std::is_sorted_until(first, last) == last;
}
这样的用法还是挺多的。
根据这篇文章,
std::unique(begin(nums), end(nums)) != end(nums)
说实在的,这个用法还是搞蒙我了。
一个可能的实现就是:
template<class ForwardIt>
ForwardIt unique(ForwardIt first, ForwardIt last)
{
if (first == last)
return last;
ForwardIt result = first;
while (++first != last) {
if (!(*result == *first) && ++result != first) {
*result = std::move(*first);
}
}
return ++result;
}
最近一段时间打算跟着raspberry做一些实验。
The red lead should be connected to 5V if you want to power via the cable, see
below for details
The black lead to GND (3rd pin down)
The white lead to TXD on the Pi (4th pin down)
The green lead to RXD on the pI (5th pin down)
3 - GND
9 - TXD
10 - RXD
华为云 这里有一系列文章介绍的设计模式,但是是通过c语言为载体的,暂时记录在这里。