`
xuning2516
  • 浏览: 7573 次
  • 性别: Icon_minigender_1
  • 来自: 江西
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论
文章列表
有一些概念还是要补补课了。 1 标量(scalar)与矢量相对。 标量:只有大小没有方向的量。C++ : Intergral(including bool and charaters) floating_point,enumeration,pointer,member pointer,std::nullptr. 矢量:有大小还有方向的量。
C++ standard library P132看到一个新的概念first-class object.但是什么是first-class object? 下面是来自维基百科的解释: A first-class object is one that can be dynamically created, destroyed or passed as an argument.So, for example, all objects in C++ are also first-class objects. They can be created or destroyed through use ...
这段时间看C++标准库,看到有一个求公共类型的实用函数common_type<>;其实现是如下: template<typename T1,typename T2> struct common_type<T1,T2> { typedef decltype(true?declval<T1>(),declval<T2>()) type; }刚开始还觉得奇怪,条件永远为true,不就是直接计算T1吗,想当然的以为产生公共类型不就是T1的类型吗?后然通过一个实例上机实验才发现不是这么回事。于是找到关于条件运算符的说明;我们知道条件运 ...
C++11 提供了许多的类型特征和型别实用函数。 1 declval 01122 /// declval 01123 template<typename _Tp> 01124 struct __declval_protector 01125 { 01126 static const bool __stop = false; 01127 static typename add_rvalue_reference<_Tp>::type __delegate(); 01128 }; 01129 01130 te ...
C++11提供了compile_time fractions andcompile-time rational arithmetic support。支持编译时常量。 头文件 <ratio> 来看ratio是怎么定义的 00152 template<intmax_t _Num, intmax_t _Den = 1> 00153 struct ratio 00154 { 00155 static_assert(_Den != 0, "denominator cannot be zero"); 00156 ...
表示时间方法是时间的基点timepoint+duaration的形式; 而变表示时间的类型有C tm结构体 struct tm { int tm_sec; /*秒,正常范围0-59, 但允许至61*/ int tm_min; /*分钟,0-59*/ int tm_hour; /*小时, 0-23*/ int tm_mday; /*日,即一个月中的第几天,1-31*/ int tm_mon; /*月, 从一月算起,0-11*/ 1+p->tm_mon; int tm_year; /*年, 从1900至今已经多少年*/ 190 ...
forward_list 源码学习 //forward_list的迭代器是forward_iterator,因此在forward list中需要注意保存前面一个元素的iterator,方便插入和删除。auto posbefore=flist.before_begin();for(auto pos=flist.begin();pos!=flist.end();++pos,++posbefore) 例如在remove_if的成员函数 ,删除的是当前元素的后一个元素。 template <class _Tp, class _Alloc> template <class ...
在stl中既有通用函数,又有相同成员函数主要表现在list中。 以remove为例 list<int> coll; // insert elements from 6 to 1 and 1 to 6 for (int i=1; i<=6; ++i) { coll.push_front(i); coll.push_back(i); } // print all elements of the collection cout << "pre: "; cop ...
本文来自http://www.cplusplus.com/reference/stl/ Member map This is a comparison chart with the different member functions present on each of the different containers:Legend: C++98 Available since C++98 C++11 New in C++11 Sequence containers Headers
C++11中新增了forward_list,头文件是 <forward_list>这个container是一个单向链表,在sgi stl中对应的是slist 数据结构中数据项保存的是头节点,尾节点初始化为0,表示链表的end()。 template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) > class slist : private _Slist_base<_Tp,_Alloc> { // requirements: __STL_CLASS_REQUIRES(_Tp, _As ...
size_type size() const { size_type __result = 0; distance(begin(), end(), __result); return __result; } 在sgi stl的实现版本中看到关于size member的实现。 这里的distance是一个全局函数。 对于random_access iterator 而言是两个迭代器相减,具有O(1)的复杂度,而对于其他类型的迭代器则是++first到last的形式,具有O(n)的复杂度。 Why islist<> ...
Global site tag (gtag.js) - Google Analytics