C++之std::tuple(二) : 揭秘底层实现原理

相关系列文章

C++之std::tuple(二) : 揭秘底层实现原理

C++三剑客之std::any(一) : 使用

C++之std::tuple(一) : 使用精讲(全)

C++三剑客之std::variant(一) : 使用

C++三剑客之std::variant(二):深入剖析

深入理解可变参数(va_list、std::initializer_list和可变参数模版)

std::apply源码分析

目录

1.std::tuple存储设计

2.std::tuple构造

3.std::tuple_size

4.std::get<>访问值

5.operator=

6._Equals

7.总结


之前的章节中讲解std::tuple的使用和一些注意事项,接下来我们就以vs2019的std::tuple的实现来讲解它的底层实现原理。

1.std::tuple存储设计

std::tuple存储的递归写法基于这样的思想:一个包含N(N>0)个元素的元组可以存储为一个元素(第1个元素,或者说是列表的头部)加上一个包含N-1个元素的元组(尾部),而包含0个元素的元组是单独的特殊情况。下面看一下示例:

std::tuple<bool, int, double, std::string>  a(true, 1, 3.0, "1112222");

因此,一个包含4个元素的元组a的递归构造如下:

1) 第一层递归。准备存储a的第一个元素true,剩下的是 std:tuple<int,double,std::string> 对象。

2) 第二层递归。准备存储a的第二个元素1,剩下的是 std::tuple<double,std::string> 对象。

3) 第三层递归。准备存储a第三个元素3.0, 剩下的是 std::tuple<std::string> 对象。

4) 第四层递归。准备存储a第四个元素"1112222",剩余的是std::tuple<>,遇到std::tuple<>递归结束。此时a的才开始存储元素,并且存储元素是从"1112222"开始,然后递归开始返回。

5) 返回到第3步的递归,存储duble类型的3.0。

6) 返回到第2步的递归,存储第int类型的1。

7) 返回到第1步的递归,存储第bool类型的true。

也就是说,std::tuple 的构造函数中,最后一个传入的元素最先构造,最先传入的元素最后一个构造,符合递归顺序,即入栈顺序。下面从源码角度,具体来看看 std::tuple 的实现。

template <class _This, class... _Rest>
class tuple<_This, _Rest...> : private tuple<_Rest...> { // recursive tuple definition
public:using _This_type = _This; //当前元素using _Mybase    = tuple<_Rest...>; //余下的元素//以下都是构造函数,罗列了部分template <class _Tag, class _This2, class... _Rest2, enable_if_t<is_same_v<_Tag, _STD _Exact_args_t>, int> = 0>constexpr tuple(_Tag, _This2&& _This_arg, _Rest2&&... _Rest_arg): _Mybase(_Exact_args_t{}, _STD forward<_Rest2>(_Rest_arg)...), _Myfirst(_STD forward<_This2>(_This_arg)) {}template <class _Tag, class _Tpl, size_t... _Indices, enable_if_t<is_same_v<_Tag, _STD _Unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, _Tpl&& _Right, index_sequence<_Indices...>);template <class _Tag, class _Tpl, enable_if_t<is_same_v<_Tag, _STD _Unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, _Tpl&& _Right): tuple(_Unpack_tuple_t{}, _STD forward<_Tpl>(_Right),make_index_sequence<tuple_size_v<remove_reference_t<_Tpl>>>{}) {}...//获取余下的元素类,不带constconstexpr _Mybase& _Get_rest() noexcept { // get reference to rest of elementsreturn *this;}//获取余下的元素类,带constconstexpr const _Mybase& _Get_rest() const noexcept { // get const reference to rest         of elementsreturn *this;}...//template <size_t _Index, class... _Types>friend constexpr tuple_element_t<_Index, tuple<_Types...>>& get(tuple<_Types...>& _Tuple) noexcept;template <size_t _Index, class... _Types>friend constexpr const tuple_element_t<_Index, tuple<_Types...>>& get(const tuple<_Types...>& _Tuple) noexcept;template <size_t _Index, class... _Types>friend constexpr tuple_element_t<_Index, tuple<_Types...>>&& get(tuple<_Types...>&& _Tuple) noexcept;template <size_t _Index, class... _Types>friend constexpr const tuple_element_t<_Index, tuple<_Types...>>&& get(const tuple<_Types...>&& _Tuple) noexcept;template <size_t _Index, class... _Types>friend constexpr auto&& _Tuple_get(tuple<_Types...>&& _Tuple) noexcept;template <class _Ty, class... _Types>friend constexpr _Ty& get(tuple<_Types...>& _Tuple) noexcept;template <class _Ty, class... _Types>friend constexpr const _Ty& get(const tuple<_Types...>& _Tuple) noexcept;template <class _Ty, class... _Types>friend constexpr _Ty&& get(tuple<_Types...>&& _Tuple) noexcept;template <class _Ty, class... _Types>friend constexpr const _Ty&& get(const tuple<_Types...>&& _Tuple) noexcept;//包装的当前的元素类,_Tuple_val<_This> _Myfirst; // the stored element    
};

        从上面的代码看到,std::tuple的递归继承用到了private继承,说明各个元素都是独立的,互相没有关系。std::tuple的元素之间是一种组合的关系。另外一个是private继承可以造成empty base最优化,这对致力于“对象尺寸最小化”的程序开发者而言,可能很重要。

        那么,tuple是如何存储其中的元素呢?

_Tuple_val<_This> _Myfirst; // the stored element

原来,它有个成员叫_Myfirst,它就是用来存储_This类型的变量的。你会看到_Myfirst的类型不是_This而是_Tuple_val<_This>,其实,_Tuple_val又是一个类模板,它的代码这里就不展开了,简而言之,它的作用是存储一个tuple中的变量。_Myfirst._Val才是真正的元素。从_Tuple_val的定义可以看出:

template <class _Ty>
struct _Tuple_val { // stores each value in a tupleconstexpr _Tuple_val() : _Val() {}template <class _Other>constexpr _Tuple_val(_Other&& _Arg) : _Val(_STD forward<_Other>(_Arg)) {}template <class _Alloc, class... _Other, enable_if_t<!uses_allocator_v<_Ty, _Alloc>, int> = 0>constexpr _Tuple_val(const _Alloc&, allocator_arg_t, _Other&&... _Arg) : _Val(_STD forward<_Other>(_Arg)...) {}template <class _Alloc, class... _Other,enable_if_t<conjunction_v<_STD uses_allocator<_Ty, _Alloc>,_STD is_constructible<_Ty, _STD allocator_arg_t, const _Alloc&, _Other...>>,int> = 0>constexpr _Tuple_val(const _Alloc& _Al, allocator_arg_t, _Other&&... _Arg): _Val(allocator_arg, _Al, _STD forward<_Other>(_Arg)...) {}template <class _Alloc, class... _Other,enable_if_t<conjunction_v<_STD uses_allocator<_Ty, _Alloc>,_STD negation<_STD is_constructible<_Ty, _STD allocator_arg_t, const _Alloc&, _Other...>>>,int> = 0>constexpr _Tuple_val(const _Alloc& _Al, allocator_arg_t, _Other&&... _Arg): _Val(_STD forward<_Other>(_Arg)..., _Al) {}_Ty _Val;
};

在std::tuple类中定义_Myfirst的权限是public的,所以对外面而言是直接访问元素值的。

通过上面的分析,a中定义的类和类的继承关系图如下所示:

class std::tuple<>;
class std::tuple<std::string>;
class std::tuple<double, std::string>;
class std::tuple<int, double, std::string>;
class std::tuple<bool, int, double, std::string>;

内存的分布图如下:

2.std::tuple构造

tuple的构造函数就是初始化_Myfirst和_MyBase,当然,_MyBase也要进行么一个过程,直到tuple<>。

//分类构造
template <class _Tag, class _This2, class... _Rest2, enable_if_t<is_same_v<_Tag, _STD _Exact_args_t>, int> = 0>constexpr tuple(_Tag, _This2&& _This_arg, _Rest2&&... _Rest_arg): _Mybase(_Exact_args_t{}, _STD forward<_Rest2>(_Rest_arg)...), _Myfirst(_STD forward<_This2>(_This_arg)) {}template <class _Tag, class _Tpl, size_t... _Indices, enable_if_t<is_same_v<_Tag, _STD _Unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, _Tpl&& _Right, index_sequence<_Indices...>);template <class _Tag, class _Tpl, enable_if_t<is_same_v<_Tag, _STD _Unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, _Tpl&& _Right): tuple(_Unpack_tuple_t{}, _STD forward<_Tpl>(_Right),make_index_sequence<tuple_size_v<remove_reference_t<_Tpl>>>{}) {}template <class _Tag, class _Alloc, class _This2, class... _Rest2,enable_if_t<is_same_v<_Tag, _STD _Alloc_exact_args_t>, int> = 0>constexpr tuple(_Tag, const _Alloc& _Al, _This2&& _This_arg, _Rest2&&... _Rest_arg): _Mybase(_Alloc_exact_args_t{}, _Al, _STD forward<_Rest2>(_Rest_arg)...),_Myfirst(_Al, allocator_arg, _STD forward<_This2>(_This_arg)) {}template <class _Tag, class _Alloc, class _Tpl, size_t... _Indices,enable_if_t<is_same_v<_Tag, _STD _Alloc_unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, const _Alloc& _Al, _Tpl&& _Right, index_sequence<_Indices...>);template <class _Tag, class _Alloc, class _Tpl, enable_if_t<is_same_v<_Tag, _STD _Alloc_unpack_tuple_t>, int> = 0>constexpr tuple(_Tag, const _Alloc& _Al, _Tpl&& _Right): tuple(_Alloc_unpack_tuple_t{}, _Al, _STD forward<_Tpl>(_Right),make_index_sequence<tuple_size_v<remove_reference_t<_Tpl>>>{}) {}//根据入口参数的不同分派到不同的构造函数
template <class _This2, class... _Rest2,enable_if_t<conjunction_v<_STD _Tuple_perfect_val<tuple, _This2, _Rest2...>,_STD _Tuple_constructible_val<tuple, _This2, _Rest2...>>,int> = 0>constexpr explicit(_Tuple_conditional_explicit_v<tuple, _This2, _Rest2...>) tuple(_This2&& _This_arg,_Rest2&&... _Rest_arg) noexcept(_Tuple_nothrow_constructible_v<tuple, _This2, _Rest2...>) // strengthened: tuple(_Exact_args_t{}, _STD forward<_This2>(_This_arg), _STD forward<_Rest2>(_Rest_arg)...) {}tuple(const tuple&) = default;
tuple(tuple&&)      = default;tuple& operator=(const volatile tuple&) = delete;

        它还提供了默认拷贝构造函数和移动构造函数(移动语义是C++11中新增的特性,可以参考C++之std::move(移动语义)-CSDN博客)。其实,它还有很多构造函数,写起来挺热闹,无非就是用不同的方式为它赋初值,故省略。

        上面的构造函数是根据_tag的不同被分派到不同的构造函数,它叫标签派发。源码中定义了如下的标签:

struct _Exact_args_t {explicit _Exact_args_t() = default;
}; // tag type to disambiguate construction (from one arg per element)struct _Unpack_tuple_t {explicit _Unpack_tuple_t() = default;
}; // tag type to disambiguate construction (from unpacking a tuple/pair)struct _Alloc_exact_args_t {explicit _Alloc_exact_args_t() = default;
}; // tag type to disambiguate construction (from an allocator and one arg per element)struct _Alloc_unpack_tuple_t {explicit _Alloc_unpack_tuple_t() = default;
}; // tag type to disambiguate construction (from an allocator and unpacking a tuple/pair)

3.std::tuple_size

先看一下源码:

template <class _Ty, _Ty _Val>
struct integral_constant {static constexpr _Ty value = _Val;using value_type = _Ty;using type       = integral_constant;constexpr operator value_type() const noexcept {return value;}_NODISCARD constexpr value_type operator()() const noexcept {return value;}
};// TUPLE INTERFACE TO tuple
template <class... _Types>
struct tuple_size<tuple<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {}; // size of tupletemplate <class _Ty1, class _Ty2>
struct tuple_size<pair<_Ty1, _Ty2>> : integral_constant<size_t, 2> {}; // size of pair

std::integral_constant 包装特定类型的静态常量。它是 C++ 类型特征的基类。

std::tuple_size利用sizeof...求得可变参数的个数。

4.std::get<>访问值

先看一下tuple_element,tuple_element是获取tuple的元素,包括_Myfirst和_MyBase,源码:

//tuple<>
template <size_t _Index>
struct _MSVC_KNOWN_SEMANTICS tuple_element<_Index, tuple<>> { // enforce bounds checkingstatic_assert(_Always_false<integral_constant<size_t, _Index>>, "tuple index out of bounds");
};//tuple的_index == 0
template <class _This, class... _Rest>
struct _MSVC_KNOWN_SEMANTICS tuple_element<0, tuple<_This, _Rest...>> { // select first elementusing type = _This;// MSVC assumes the meaning of _Ttype; remove or rename, but do not change semanticsusing _Ttype = tuple<_This, _Rest...>;
};//tuple的_index > 0
template <size_t _Index, class _This, class... _Rest>
struct _MSVC_KNOWN_SEMANTICS tuple_element<_Index, tuple<_This, _Rest...>>: tuple_element<_Index - 1, tuple<_Rest...>> {}; // recursive tuple_element definition//pair
template <size_t _Idx, class _Ty1, class _Ty2>
struct _MSVC_KNOWN_SEMANTICS tuple_element<_Idx, pair<_Ty1, _Ty2>> {static_assert(_Idx < 2, "pair index out of bounds");using type = conditional_t<_Idx == 0, _Ty1, _Ty2>;
};template <size_t _Index, class _Tuple>
using tuple_element_t = typename tuple_element<_Index, _Tuple>::type;

通过_Index获取tuple元素:

template <size_t _Index, class... _Types>
_NODISCARD constexpr tuple_element_t<_Index, tuple<_Types...>>& get(tuple<_Types...>& _Tuple) noexcept {using _Ttype = typename tuple_element<_Index, tuple<_Types...>>::_Ttype;return static_cast<_Ttype&>(_Tuple)._Myfirst._Val;
}template <size_t _Index, class... _Types>
_NODISCARD constexpr const tuple_element_t<_Index, tuple<_Types...>>& get(const tuple<_Types...>& _Tuple) noexcept {using _Ttype = typename tuple_element<_Index, tuple<_Types...>>::_Ttype;return static_cast<const _Ttype&>(_Tuple)._Myfirst._Val;
}template <size_t _Index, class... _Types>
_NODISCARD constexpr tuple_element_t<_Index, tuple<_Types...>>&& get(tuple<_Types...>&& _Tuple) noexcept {using _Ty    = tuple_element_t<_Index, tuple<_Types...>>;using _Ttype = typename tuple_element<_Index, tuple<_Types...>>::_Ttype;return static_cast<_Ty&&>(static_cast<_Ttype&>(_Tuple)._Myfirst._Val);
}template <size_t _Index, class... _Types>
_NODISCARD constexpr const tuple_element_t<_Index, tuple<_Types...>>&& get(const tuple<_Types...>&& _Tuple) noexcept {using _Ty    = tuple_element_t<_Index, tuple<_Types...>>;using _Ttype = typename tuple_element<_Index, tuple<_Types...>>::_Ttype;return static_cast<const _Ty&&>(static_cast<const _Ttype&>(_Tuple)._Myfirst._Val);
}

上述代码分析get<index>的流程:

1)通过_Index递归构造出类 tuple_element_t

2)   获取当前元素 _MyFirst.Val

通过_Ty获取tuple元素:

//辅助类
template <class _Ty, class _Tuple>
struct _Tuple_element {}; // backstop _Tuple_element definitiontemplate <class _This, class... _Rest>
struct _Tuple_element<_This, tuple<_This, _Rest...>> { // select first elementstatic_assert(!_Is_any_of_v<_This, _Rest...>, "duplicate type T in get<T>(tuple)");using _Ttype = tuple<_This, _Rest...>;
};template <class _Ty, class _This, class... _Rest>
struct _Tuple_element<_Ty, tuple<_This, _Rest...>> { // recursive _Tuple_element definitionusing _Ttype = typename _Tuple_element<_Ty, tuple<_Rest...>>::_Ttype;
};//通过_Ty  get
template <class _Ty, class... _Types>
_NODISCARD constexpr _Ty& get(tuple<_Types...>& _Tuple) noexcept {using _Ttype = typename _Tuple_element<_Ty, tuple<_Types...>>::_Ttype;return static_cast<_Ttype&>(_Tuple)._Myfirst._Val;
}template <class _Ty, class... _Types>
_NODISCARD constexpr const _Ty& get(const tuple<_Types...>& _Tuple) noexcept {using _Ttype = typename _Tuple_element<_Ty, tuple<_Types...>>::_Ttype;return static_cast<const _Ttype&>(_Tuple)._Myfirst._Val;
}template <class _Ty, class... _Types>
_NODISCARD constexpr _Ty&& get(tuple<_Types...>&& _Tuple) noexcept {using _Ttype = typename _Tuple_element<_Ty, tuple<_Types...>>::_Ttype;return static_cast<_Ty&&>(static_cast<_Ttype&>(_Tuple)._Myfirst._Val);
}template <class _Ty, class... _Types>
_NODISCARD constexpr const _Ty&& get(const tuple<_Types...>&& _Tuple) noexcept {using _Ttype = typename _Tuple_element<_Ty, tuple<_Types...>>::_Ttype;return static_cast<const _Ty&&>(static_cast<const _Ttype&>(_Tuple)._Myfirst._Val);
}

上述代码分析get<_Ty>的流程:

1)通过_Ty递归构造出类 _Tuple_element

2)   获取当前元素 _MyFirst.Val

5.operator=

tuple重载了赋值符号(=),这样,tuple之间是可以赋值的。

    tuple& operator=(const volatile tuple&) = delete;//以下是特殊情况是可以赋值的template <class _Myself = tuple, class _This2 = _This,enable_if_t<conjunction_v<_STD _Is_copy_assignable_no_precondition_check<_This2>,_STD _Is_copy_assignable_no_precondition_check<_Rest>...>,int> = 0>_CONSTEXPR20 tuple& operator=(_Identity_t<const _Myself&> _Right) noexcept(conjunction_v<is_nothrow_copy_assignable<_This2>, is_nothrow_copy_assignable<_Rest>...>) /* strengthened */ {_Myfirst._Val = _Right._Myfirst._Val;_Get_rest()   = _Right._Get_rest();return *this;}template <class _Myself = tuple, class _This2 = _This,enable_if_t<conjunction_v<_STD _Is_move_assignable_no_precondition_check<_This2>,_STD _Is_move_assignable_no_precondition_check<_Rest>...>,int> = 0>_CONSTEXPR20 tuple& operator=(_Identity_t<_Myself&&> _Right) noexcept(conjunction_v<is_nothrow_move_assignable<_This2>, is_nothrow_move_assignable<_Rest>...>) {_Myfirst._Val = _STD forward<_This>(_Right._Myfirst._Val);_Get_rest()   = _STD forward<_Mybase>(_Right._Get_rest());return *this;}template <class... _Other, enable_if_t<conjunction_v<_STD negation<_STD is_same<tuple, _STD tuple<_Other...>>>,_STD _Tuple_assignable_val<tuple, const _Other&...>>,int> = 0>_CONSTEXPR20 tuple& operator=(const tuple<_Other...>& _Right) noexcept(_Tuple_nothrow_assignable_v<tuple, const _Other&...>) /* strengthened */ {_Myfirst._Val = _Right._Myfirst._Val;_Get_rest()   = _Right._Get_rest();return *this;}template <class... _Other, enable_if_t<conjunction_v<_STD negation<_STD is_same<tuple, _STD tuple<_Other...>>>,_STD _Tuple_assignable_val<tuple, _Other...>>,int> = 0>_CONSTEXPR20 tuple& operator=(tuple<_Other...>&& _Right) noexcept(_Tuple_nothrow_assignable_v<tuple, _Other...>) /* strengthened */ {_Myfirst._Val = _STD forward<typename tuple<_Other...>::_This_type>(_Right._Myfirst._Val);_Get_rest()   = _STD forward<typename tuple<_Other...>::_Mybase>(_Right._Get_rest());return *this;}template <class _First, class _Second,enable_if_t<_Tuple_assignable_v<tuple, const _First&, const _Second&>, int> = 0>_CONSTEXPR20 tuple& operator=(const pair<_First, _Second>& _Right) noexcept(_Tuple_nothrow_assignable_v<tuple, const _First&, const _Second&>) /* strengthened */ {_Myfirst._Val             = _Right.first;_Get_rest()._Myfirst._Val = _Right.second;return *this;}

赋值符号返回左边的引用,这种行为和C++的内置类型是一致的。_Get_rest是tuple的成员函数,作用是把除了_Myfirst之外的那些元素拿出来。

6._Equals

    //tuple内置函数template <class... _Other>constexpr bool _Equals(const tuple<_Other...>& _Right) const {return _Myfirst._Val == _Right._Myfirst._Val && _Mybase::_Equals(_Right._Get_rest());}//重载operator==template <class... _Types1, class... _Types2>
_NODISCARD constexpr bool operator==(const tuple<_Types1...>& _Left, const tuple<_Types2...>& _Right) {static_assert(sizeof...(_Types1) == sizeof...(_Types2), "cannot compare tuples of different sizes");return _Left._Equals(_Right);
}

其中进行了静态断言,如果两个tuple的元素个数不相同,会引发一个编译时的错误。如果对应的类型不能用==进行比较,在模板特化时也会引发编译期的错误,例如,tuple<std::string, int>不能和tuple<int, char>比较,因为std::string和int是不能用==进行比较的。

7.总结

终于写完了,也是想了好久才写的,涉及到的知识点主要是模版推导。写的不好的地方,欢迎批评指正;如果觉得好,点个赞,收藏关注!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/491018.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue:实现顶部消息横向滚动通知

前言 系统顶部展示一个横向滚动的消息通知&#xff0c;就是消息内容从右往左一直滚动。 效果如下&#xff1a; 代码 使用 <template><div class"notic-bar"><img :src"notic" class"notice-img" /><div class"noti…

牛客周赛 Round 33 解题报告 | 珂学家 | 思维场

前言 整体评价 感觉这场更偏思维&#xff0c;F题毫无思路&#xff0c;但是可以模拟骗点分, E题是dij最短路. A. 小红的单词整理 类型: 签到 w1,w2 input().split() print (w2) print (w1)B. 小红煮汤圆 思路: 模拟 可以从拆包的角度去构建模拟 注意拆一包&#xff0c;可以…

抖音视频抓取软件的优势|视频评论内容提取器|批量视频下载

抖音视频抓取软件在市场上的优势明显&#xff1a; 功能强大&#xff1a;我们的软件支持关键词搜索抓取和分享链接单一视频提取两种方式&#xff0c;满足用户不同的需求。同时&#xff0c;支持批量处理数据&#xff0c;提高用户获取视频的效率。 操作简单&#xff1a;我们的软件…

【技术分享】使用nginx完成动静分离➕集成SpringSession➕集成sentinel➕集成seata

&#x1f973;&#x1f973;Welcome 的Huihuis Code World ! !&#x1f973;&#x1f973; 接下来看看由辉辉所写的关于技术点的相关分享吧 目录 &#x1f973;&#x1f973;Welcome 的Huihuis Code World ! !&#x1f973;&#x1f973; 一、 使用nginx完成动静分离 1.下载…

人工智能在测绘行业的应用与挑战

目录 一、背景 二、AI在测绘行业的应用方向 1. 自动化特征提取 2. 数据处理与分析 3. 无人机测绘 4. 智能导航与路径规划 5. 三维建模与可视化 6. 地理信息系统&#xff08;GIS&#xff09;智能化 三、发展前景 1. 技术融合 2. 精准测绘 3. 智慧城市建设 4. 可…

SSM---Mybatis查询数据库的功能

Mybatis查询数据库的功能流程&#xff1a; 在maven中加入mybatis依赖&#xff0c;mysql驱动依赖创建一张student表创建表对应的实体类&#xff1a;student类&#xff0c;用来保存表中的每行数据创建持久层的DAO接口&#xff0c;用来定义操作数据库的方法创建这个表对应的sql映…

市场复盘总结 20240223

仅用于记录当天的市场情况&#xff0c;用于统计交易策略的适用情况&#xff0c;以便程序回测 短线核心&#xff1a;不参与任何级别的调整&#xff0c;采用龙空龙模式 一支股票 10%的时候可以操作&#xff0c; 90%的时间适合空仓等待 二进三&#xff1a; 进级率中 57% 最常用的…

1分钟带你学会Python的pass关键字和range函数

1.pass 关键字 pass关键字在 python 中没有任何实际意义&#xff0c;主要是用来完成占位的操作&#xff0c;保证语句的完整性 age int(input(请输入您的年龄&#xff1a;))if age > 18: pass # pass 在此处没有任何意义&#xff0c;只是占位 print(欢迎光临。。。…

基于Clion+stm32cubemx+rt-thread os进行环境搭建

前言 RT-Thread文档中心Clion开发STM32的环境搭建,请参考之前的文章本次使用的芯片为STM32F407VET6,其他芯片相似.项目创建 使用STM32CubeMx快速生成项目工程,此步骤的话可以参考官方文档 基础配置如下

操作符详解3

✨✨ 欢迎大家来到莉莉的博文✨✨ &#x1f388;&#x1f388;养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; 前面我们已经讲过算术操作符、赋值操作符、逻辑操作符、条件操作符和部分的单目操作 符&#xff0c;今天继续介绍一部分。 目录 1.操作符的分类 2…

babylonjs入门模

基于babylonjs封装的一些功能和插件 &#xff0c;希望有更多的小伙伴一起玩babylonjs&#xff1b; 欢迎加群&#xff1a;464146715 官方文档 中文文档 最小模版 ​ 代码如下&#xff1a; 在react中使用 import React, { FC, useCallback, useEffect, useRef, useState } f…

Cover和contain属性

一.背景的盒子 代码&#xff1a; <body><div class"box"></div><style>.box {width: 500px;height: 500px;border: 1px solid #ccc;background: url(./20191017095131790.png) no-repeat;}</style></body> 盒子的宽度和高度是…