C++迈向精通:STL设计机制之运算检查(含部分源码解析)

STL设计机制之支持运算检查

文章目录

  • STL设计机制之支持运算检查
    • `__STL_REQUIRES`
    • `_LessThanComparable`
      • `_STL_ERROR::__less_than_comparable_requirement_violation`
    • STL运算检查方法的特点
      • `do{...}while` 的优点
        • 场景1
        • 场景2
      • `__x = __x`
    • 自己写一个运算检查

单说这个标题可能有点奇怪,但是如果我用下面的一段话给你说你大概就能明白这一篇文章在讲什么了:

sort 函数在排序之前会先进行一个检查,那就是是否支持小于运算符:

源码是这样写的:

1这行代码的会对类型进行检查,看看类型是否支持小于运算,如果不支持,LSP会直接检查并且报错。

其实,进行运算符号的支持判断并不难,我们只需要写一段对应的代码即可,但是STL中的源码就很神奇,他做到了不消耗系统资源而达到代码检查的目的。

来一起看一看他是怎么做的:

__STL_REQUIRES

先来看看这是一个什么东西:

根据编程规范,这个东西大概率是一个宏(因为他全是大写),我们跳转到源码看一看:

2
一看,果然是一个宏,这个代码使用一个 do{ }while 循环将其中的代码段包裹了起来,在代码中,我们使用了一个返回值为空的函数指针类型:

void (*__x)(__type_var) = __concept##_concept_specification<__type_var>::__concept##_requirment_violation; __x = __x;

宏的第一个参数很明显是一个类型,我们在外部可以传入类,第二个参数似乎是一个功能类,用于代码检查,在上层,他这里传入了一个名为 _LessThanComparable 的工具类,猜测应该是用于是否可以进行小于号运算的检查的一个工具类。

宏生成了一个函数指针,指向 _LessThanComparable 这个类中的一个成员方法 _LessThanComparable_requirement_violation

最后 __x = __x 执行了一次自己给自己赋值的操作。

_LessThanComparable

_LessThanComparable 中又调用了 _STL_ERROR::__less_than_comparable_requirement_violation 这个方法。
3
根据英文语义也能看出,这个函数的功能似乎是与STL的错误检查有关系,我们继续往下走:

_STL_ERROR::__less_than_comparable_requirement_violation

4
终于算是到达源码尽头了!在这个方法中,返回类型是我们传入的 _Type 也就是我们需要待比较的类型,然后使用 if 语句将他们的比较操作执行了一遍,最后返回。

如果两个对象不能比较的话,LSP 会报错,在这里,只需要调用他们的运算方法就可以达到让代码检查的目的。

那么,为什么还要大废周章的使用一个宏和函数指针呢?

在上层,还使用了 do {...} whlie 来封装代码,这样做的意义是什么呢?

STL运算检查方法的特点

do{...}while 的优点

试想如下场景:

场景1

假设你的代码前面有个函数声明,但是你忘记加分号了:

int func()
__STL_REQUESTS(..., ...)
...

这会发生什么呢?

如果没有 do{}while 这段代码不会被 LSP 发现并且报错,因为他被替换成了代码的一部分。

场景2

假设你没有 du{...}while 如果我需要让你在宏的代码中执行到一半并且退出到外层函数,你会怎么做?

答案是做不了,没有了 do{...}while ,是不可以让代码退出到外层的,因为被宏替换掉之后,这段代码会成为所谓外层函数的一部分,因此,我们需要一层类似于函数的结构将其封装起来,这个时候,do{...}while(0) 就会起到作用。

do{...}while(0) 中,只需要一个 break 就可以让函数停止并退出到外层函数。

do{…}while(0) 大大提高的代码的灵活性,并且减少了一语法歧义

__x = __x

这段代码的作用是什么呢?很简单,由于 __x 是一个函数指针类型,因此,如果编译器检测到一个变量初始化之后没有被使用,那么很有可能会将其优化掉。

自己写一个运算检查

以小于号比较运算检查为例子,我们可以这样来实现:

首先写一个宏:

#define __STL_REQUESTS(type, __concept) do { \function<void()> __x = __concept<type>::__operator_concept; \__x = __x; \
} while(0)

为了方便,我们之间使用 function 代替函数指针。

关于工具类:

template <typename type>
class _LessThanCompare {
public:static void __operator_concept() {function<type(type, type)> __x = __inner__operator_concept;return ;}static type __inner__operator_concept(type a, type b) {if (a < b) return a;return b;}
};

我们在函数内部进行了一次封装,这样做的目的是统一宏中 function 的模板参数。
在函数内部我们再进行不同参数类型的传参。这样就能做到类型检查啦!

来看一下效果!!

我们先设计一个没有重载小于运算的类:

class Base {
public://bool operator<(Base &obj) const {//    return true;//}
};

然后在主函数中执行:

int main() {__STL_REQUESTS(Base, _LessThanCompare);
}

编译出现下面的报错:

5完整错误信息其实很长:

SRL_REQUIRES.cpp: In instantiation of ‘static type _LessThanCompare<type>::__inner__operator_concept(type, type) [with type = Base]’:
SRL_REQUIRES.cpp:36:36:   required from ‘static void _LessThanCompare<type>::__operator_concept() [with type = Base]’
SRL_REQUIRES.cpp:111:5:   required from here
SRL_REQUIRES.cpp:40:15: error: no match for ‘operator<(operand types are ‘Base’ and ‘Base’)if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,from /usr/include/c++/7/bits/char_traits.h:39,from /usr/include/c++/7/ios:40,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/stl_pair.h:454:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:454:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::pair<_T1, _T2>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,from /usr/include/c++/7/bits/char_traits.h:39,from /usr/include/c++/7/ios:40,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/stl_iterator.h:308:5: note: candidate: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)operator<(const reverse_iterator<_Iterator>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:308:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::reverse_iterator<_Iterator>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,from /usr/include/c++/7/bits/char_traits.h:39,from /usr/include/c++/7/ios:40,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/stl_iterator.h:346:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)operator<(const reverse_iterator<_IteratorL>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:346:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::reverse_iterator<_Iterator>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,from /usr/include/c++/7/bits/char_traits.h:39,from /usr/include/c++/7/ios:40,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/stl_iterator.h:1145:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)operator<(const move_iterator<_IteratorL>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1145:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::move_iterator<_IteratorL>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,from /usr/include/c++/7/bits/char_traits.h:39,from /usr/include/c++/7/ios:40,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/stl_iterator.h:1151:5: note: candidate: template<class _Iterator> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)operator<(const move_iterator<_Iterator>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1151:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::move_iterator<_IteratorL>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/string:52:0,from /usr/include/c++/7/bits/locale_classes.h:40,from /usr/include/c++/7/bits/ios_base.h:41,from /usr/include/c++/7/ios:42,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/basic_string.h:6094:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6094:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/string:52:0,from /usr/include/c++/7/bits/locale_classes.h:40,from /usr/include/c++/7/bits/ios_base.h:41,from /usr/include/c++/7/ios:42,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/basic_string.h:6107:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6107:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/string:52:0,from /usr/include/c++/7/bits/locale_classes.h:40,from /usr/include/c++/7/bits/ios_base.h:41,from /usr/include/c++/7/ios:42,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/bits/basic_string.h:6119:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)operator<(const _CharT* __lhs,^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6119:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   mismatched types ‘const _CharT*’ and ‘Base’if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/ios_base.h:46:0,from /usr/include/c++/7/ios:42,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from SRL_REQUIRES.cpp:9:
/usr/include/c++/7/system_error:208:3: note: candidate: bool std::operator<(const std::error_code&, const std::error_code&)operator<(const error_code& __lhs, const error_code& __rhs) noexcept^~~~~~~~
/usr/include/c++/7/system_error:208:3: note:   no known conversion for argument 1 from ‘Base’ to ‘const std::error_code&’
/usr/include/c++/7/system_error:282:3: note: candidate: bool std::operator<(const std::error_condition&, const std::error_condition&)operator<(const error_condition& __lhs,^~~~~~~~
/usr/include/c++/7/system_error:282:3: note:   no known conversion for argument 1 from ‘Base’ to ‘const std::error_condition&’
In file included from /usr/include/c++/7/list:63:0,from SRL_REQUIRES.cpp:11:
/usr/include/c++/7/bits/stl_list.h:1918:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<(const std::__cxx11::list<_Tp, _Alloc>&, const std::__cxx11::list<_Tp, _Alloc>&)operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)^~~~~~~~
/usr/include/c++/7/bits/stl_list.h:1918:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::__cxx11::list<_Tp, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/vector:64:0,from SRL_REQUIRES.cpp:12:
/usr/include/c++/7/bits/stl_vector.h:1618:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:1618:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::vector<_Tp, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/deque:64:0,from /usr/include/c++/7/queue:60,from SRL_REQUIRES.cpp:13:
/usr/include/c++/7/bits/stl_deque.h:293:5: note: candidate: template<class _Tp, class _Ref, class _Ptr> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:293:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/deque:64:0,from /usr/include/c++/7/queue:60,from SRL_REQUIRES.cpp:13:
/usr/include/c++/7/bits/stl_deque.h:301:5: note: candidate: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:301:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/deque:64:0,from /usr/include/c++/7/queue:60,from SRL_REQUIRES.cpp:13:
/usr/include/c++/7/bits/stl_deque.h:2276:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)operator<(const deque<_Tp, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:2276:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::deque<_Tp, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/queue:64:0,from SRL_REQUIRES.cpp:13:
/usr/include/c++/7/bits/stl_queue.h:336:5: note: candidate: template<class _Tp, class _Seq> bool std::operator<(const std::queue<_Tp, _Seq>&, const std::queue<_Tp, _Seq>&)operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)^~~~~~~~
/usr/include/c++/7/bits/stl_queue.h:336:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::queue<_Tp, _Seq>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/stack:61:0,from SRL_REQUIRES.cpp:14:
/usr/include/c++/7/bits/stl_stack.h:311:5: note: candidate: template<class _Tp, class _Seq> bool std::operator<(const std::stack<_Tp, _Seq>&, const std::stack<_Tp, _Seq>&)operator<(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)^~~~~~~~
/usr/include/c++/7/bits/stl_stack.h:311:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::stack<_Tp, _Seq>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/set:60:0,from SRL_REQUIRES.cpp:15:
/usr/include/c++/7/bits/stl_tree.h:1543:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_tree.h:1543:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/set:61:0,from SRL_REQUIRES.cpp:15:
/usr/include/c++/7/bits/stl_set.h:930:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)operator<(const set<_Key, _Compare, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_set.h:930:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::set<_Key, _Compare, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/set:62:0,from SRL_REQUIRES.cpp:15:
/usr/include/c++/7/bits/stl_multiset.h:913:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)operator<(const multiset<_Key, _Compare, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_multiset.h:913:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::multiset<_Key, _Compare, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/tuple:39:0,from /usr/include/c++/7/bits/stl_map.h:63,from /usr/include/c++/7/map:61,from SRL_REQUIRES.cpp:16:
/usr/include/c++/7/array:262:5: note: candidate: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)^~~~~~~~
/usr/include/c++/7/array:262:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::array<_Tp, _Nm>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/bits/stl_map.h:63:0,from /usr/include/c++/7/map:61,from SRL_REQUIRES.cpp:16:
/usr/include/c++/7/tuple:1410:5: note: candidate: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Tps ...>&, const std::tuple<_Args2 ...>&)operator<(const tuple<_TElements...>& __t,^~~~~~~~
/usr/include/c++/7/tuple:1410:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::tuple<_Tps ...>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/map:61:0,from SRL_REQUIRES.cpp:16:
/usr/include/c++/7/bits/stl_map.h:1411:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_map.h:1411:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>if (a < b) return a;~~^~~
In file included from /usr/include/c++/7/map:62:0,from SRL_REQUIRES.cpp:16:
/usr/include/c++/7/bits/stl_multimap.h:1076:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,^~~~~~~~
/usr/include/c++/7/bits/stl_multimap.h:1076:5: note:   template argument deduction/substitution failed:
SRL_REQUIRES.cpp:40:15: note:   ‘Base’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>if (a < b) return a;~~^~~

当我们重载小于号之后:

class Base {
public:bool operator<(Base &obj) const {return true;}
};

编译通过:

7

以上就是本文的全部内容!

:wq 拜拜~~

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

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

相关文章

基于java的设计模式学习

PS &#xff1a;以作者的亲身来看&#xff0c;这东西对于初学者来说有用但不多&#xff0c;这些东西&#xff0c;更像一种经验的总结&#xff0c;在平时开发当中一般是用不到的&#xff0c;因此站在这个角度上用处不大。 1.工厂模式 1.1 简单工厂模式 我们把new 对象逻辑封装…

【VUE】v-if和v-for的优先级

v-if和v-for v-if 用来显示和隐藏元素 flag为true时&#xff0c;dom元素会被删除达到隐藏效果 <div class"boxIf" v-if"flag"></div>v-for用来进行遍历&#xff0c;可以遍历数字对象数组&#xff0c;会将整个元素遍历指定次数 <!-- 遍…

【大数据】JSON文件解析,对其文本聚类/情感分析

目录 引言 JSON&#xff08;JavaScript Object Notation&#xff09; 文本聚类K-means 基本步骤 优点 缺点 实际应用 情感分析 核心任务与应用场景 算法原理与技术 json数据集 情感分析实现 文本聚类实现 引言 JSON&#xff08;JavaScript Object Notation&#…

从系统层面认识Linux及mysql中的多表查询

为什么计算机起始时间是1970年1月1日 为什么计算机起始时间是1970年1月1日-CSDN博客https://blog.csdn.net/csdn_kou/article/details/81535452 date "%Y-%m-%d %H:%M:%S" 查看日期 sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 在数据层面 CPU不…

Nacos Derby 远程命令执行漏洞(QVD-2024-26473)

0x01 产品简介 Nacos 是一个功能强大的服务注册与发现、配置管理平台,为微服务架构和云原生应用提供了重要的基础设施支持。 0x02 漏洞概述 由于Alibaba Nacos部分版本中derby数据库默认可以未授权访问,恶意攻击者利用此漏洞可以未授权执行SQL语句,最终导致任意代码执行。…

第三届智能机械与人机交互技术学术会议(IHCIT 2024)

【北航主办丨本届SPIE独立出版丨已确认ISSN号】 第三届智能机械与人机交互技术学术会议&#xff08;IHCIT 2024&#xff09; 2024 3rd International Conference on Intelligent Mechanical and Human-Computer Interaction Technology 2024年7月27日----中国杭州&#xff0…

敲详细的springframework-amqp-rabbit源码解析

看源码时将RabbitMQ的springframework-amqp-rabbit和spring-rabbit的一套区分开&#xff0c;springboot是基于RabbitMQ的Java客户端建立了简便易用的框架。 springboot的框架下相对更多地使用消费者Consumer和监听器Listener的概念&#xff0c;这两个概念不注意区分容易混淆。…

Vatee万腾平台:智慧金融的创新引擎,驱动金融服务升级

在数字化浪潮席卷全球的今天&#xff0c;金融行业正经历着前所未有的变革与升级。Vatee万腾平台&#xff0c;作为智慧金融领域的创新先锋&#xff0c;正以其独特的技术优势、前瞻的战略布局和卓越的服务能力&#xff0c;成为推动金融服务升级的重要引擎。 智慧金融&#xff1a;…

一个关于STM32的DAC输出的遗忘点

众所周知熟练使用HAL库可以帮你解决不少stm32的开发难题&#xff0c;但是是谁让你陷入了这些难题&#xff0c;别问。 如上图所示&#xff0c;正常初始化这个模块后生成代码如下图所示&#xff1b; * DAC init function */ void MX_DAC_Init(void) {/* USER CODE BEGIN DAC_Ini…

2024年计算机软考中级【硬件工程师】面试题目汇总(附答案)

硬件工程师面试题汇总分析 1、解释一下同步电路和异步电路 解题思路 同步电路和异步电路是指同步时序电路和异步时序电路。由于存储电路中触发器的动作特点不同&#xff0c;因此可以把时序电路分为同步时序电路和异步时序电路两种。同步时序电路所有的触发器状态的变化都是在同…

【单目3D检测】smoke(1):模型方案详解

纵目发表的这篇单目3D目标检测论文不同于以往用2D预选框建立3D信息&#xff0c;而是采取直接回归3D信息&#xff0c;这种思路简单又高效&#xff0c;并不需要复杂的前后处理&#xff0c;而且是一种one stage方法&#xff0c;对于实际业务部署也很友好。 题目&#xff1a;SMOKE&…

Java 中的异常

异常&#xff1a;就是出现的问题。 在Java中异常被当成对象进行处理&#xff0c;所有的异常类都继承于Throwable类&#xff0c;如果Java提供的异常类并不能满足需求&#xff0c;用户还可以自己定义一个异常类。 下面是异常体系结构&#xff1a; Throwable又分成了Error和Exce…

vmware配置centos+配置静态ip联网+更换镜像

centos7配置参考【实战】VMware17虚拟机以及Centos7详细安装教程-CSDN博客 ip配置步骤&#xff1a; 先更改编辑虚拟网络编辑器中的内容 就按照还原默认设置来&#xff0c;设定后就是以上内容&#xff0c;然后一定要记住子网ip和子网掩码 接下来就是NAT设置&#xff1a; 网关…

PE安装系统

前些天客户的电脑坏了,需要重装系统,我们的恢复光盘安装的时候,由于主板的原因,导致进入windows安装界面,鼠标键盘没有响应,自然也就无法正常安装了. 那我们只能换个方法,PE安装试试看,那么我们需要做哪些准备工作呢? 1.制作PE启动盘,网上很多制作工具,如""U启动,…

关于 Docker Registry (镜像仓库)

什么是镜像仓库 概念 镜像仓库&#xff08;Docker Registry&#xff09;负责存储、管理和分发镜像&#xff0c;并提供了登录认证能力&#xff0c;建立了仓库的索引。 镜像仓库管理多个 Repository&#xff0c;Repository 通过命名来区分。每个 Repository 包含一个或多个镜像…

P1-AI产品经理--九五小庞

产品经理的定位 AI基于现有业务挖掘AI应用场景&#xff0c;服务提供商选择及算法定制等&#xff0c;配合已有产品完成整体产品工工资基于从事医疗行业的考虑&#xff0c;我们走的应该是AI产品经理&#xff08;软件型&#xff09; AI产品经理&#xff08;行业型&#xff09; AI…

Python爬虫(1) --基础知识

爬虫 爬虫是什么&#xff1f; spider 是一种模仿浏览器上网过程的一种程序&#xff0c;可以获取一些网页的数据 基础知识 URL 统一资源定位符 uniform resource locator http: 超文本传输协议 HyperText Transfer Protocol 默认端口 80 https: 安全的超文本传输协议 security…

通过HTML/CSS 实现各类进度条的功能。

需求&#xff1a;我们在开发中会遇到使用各式各样的进度条&#xff0c;因为当前插件里面进度条各式各样的&#xff0c;为了方便我们定制化的开发和方便修改样式&#xff0c;我们这里使用HTML和CSS样式来进行开发进度条功能。 通过本文学习我们会明白如何使用 HTML/CSS 创建各种…

复旦微核心板:基于复旦微FMQL45T900 全国产化核心板

近期开发的一款搭载复旦微FMQL45T900的全国产核心板。FMQL45T900这款是一款高度集成的国产化芯片&#xff0c;它在一个单芯片中融合了多种功能&#xff0c;特别强调的是它的国产化特性&#xff0c;即其设计、制造和知识产权完全属于中国。 处理器性能&#xff1a; 处理器架构&a…

Python和C++行人轨迹预推算和空间机器人多传感融合双图算法模型

&#x1f3af;要点 &#x1f3af;双图神经网络模型&#xff1a;最大后验推理和线性纠错码解码器 | &#x1f3af;重复结构和过约束问题超图推理模型 | &#x1f3af;无向图模型变量概率计算、和积消息传播图结构计算、隐马尔可夫模型图结构计算、矩阵图结构计算、图结构学习 |…