Comments (4)
首先回答(...)
是variadic function
,大概就是可以接受任意类型的任意数量的参数,详情见https://en.cppreference.com/w/cpp/utility/variadic。
然后不知道你清不清楚为什么有这么一坨东西,我稍微讲一下,也顺便让大家看看我说得对不对。
struct two { char a; char b; };
template <class U> static two test(...);
template <class U> static char test(typename U::iterator_category* = 0);
这里利用了SFINAE
,作用是用来检测T
这个类型有没有iterator_category
这个成员类型别名,如果有,就会匹配到template <class U> static char test(typename U::iterator_category* = 0)
然后返回类型是char
,否则匹配到template <class U> static two test(...)
返回类型是two
,注意到char
和two
的大小是不一样的。所以看到
static const bool value = sizeof(test<T>(0)) == sizeof(char);
就可以轻松靠判断test
返回类型的大小是否等于sizeof(char)
来判断T
有没有iterator_category
这个成员了,功能正好这就是类型名has_iterator_cat
描述的。以前没有concept
的时候就只能靠这样嗯造。test
没有定义是正常的,因为sizeof
运算符不会真的运行这个函数,只会推导出函数返回类型,说白了这个函数就纯纯工具人,只是用来获取类型而已。SFINAE
详情看https://en.cppreference.com/w/cpp/language/sfinae。
如果有哪里说得不对的还请指正。
from mytinystl.
其实 这个 ... 这三个点是 八成是 任意类型的意思,但是不明白这个 test 模板函数 是没有 定义的。
from mytinystl.
我想知道 这个 test 函数模板 应该是有定义的,不是很懂
from mytinystl.
楼上对的
from mytinystl.
Related Issues (20)
- 求问,项目clone不到我的ubuntu去
- 关于容器中的allocator_type get_allocator()函数 HOT 1
- 关于unorderset_set的比较操作符 HOT 2
- vs2022 C++14 运行报错 HOT 8
- address_of不能获取对象的真实地址 HOT 5
- 请问在对this指针操作时,为什么使用&*this,而不是直接返回this
- basic_string.h中erase删除 [first, last) 的元素的问题 HOT 1
- hashtable构造函数可能有问题 HOT 2
- hashtable的insert_unique_use_hint可能有问题 HOT 1
- 关于测试mystl::vector<std::string> v3找不到可匹配的destroy的问题 HOT 1
- basic_string.h:逻辑问题 HOT 4
- functional.h 类模板 `identity` 实现模板参数错误? HOT 2
- 请教下作者实现的STL相比标准库的STL整体性能略优,可能是哪些方面导致的 HOT 5
- 关于deque容器析构函数中可能会导致内存泄漏的问题 HOT 3
- vector& operator=(const vector& rhs);rhs的size大于当前对象的size并且小于等于当前的capacity时,会造成内存泄漏 HOT 1
- 你这里面的alloc.h 里面 有很大错误, 不建议阅读整个项目了. HOT 1
- uninitialized_fill_n 的模板偏特化疑问,MyTinySTL的行为与标准库不同 HOT 3
- 运行错误
- 请教一下作者,你在栈里分配千万数量级的内存,比如push_back那里,栈不会溢出吗 HOT 1
- 编译报错
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mytinystl.