社区
C语言
帖子详情
c语言实现stl
zengjie_0_2001
2006-11-03 08:29:29
请问怎么用c实现stl
用宏?
类似这样:
#define int ok
struct list
{
#ifdef int
int i;
#elifdef char
char str;
#else
char *string;
#endif
struct list *next;
};
...全文
448
6
打赏
收藏
c语言实现stl
请问怎么用c实现stl 用宏? 类似这样: #define int ok struct list { #ifdef int int i; #elifdef char char str; #else char *string; #endif struct list *next; };
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
rickerliang
2006-11-05
打赏
举报
回复
~~
youngphoneix
2006-11-05
打赏
举报
回复
这是我的一个开源项目,目的就是用C实现STL
http://gforge.osdn.net.cn/projects/ylib/
adintr
2006-11-04
打赏
举报
回复
C 没有操作符重载,如何实现 iterator, functor?
mLee79
2006-11-04
打赏
举报
回复
C 比stl自由多了, 用啥 stl , 最简单的可以这样 ....
#include <stdio.h>
#include <stdlib.h>
#define XDS_slist_init( __h__ ) ((__h__)->xd_next = (__h__))
#define XDS_slist_erase_after( __n__ , __f__ ) \
do { \
void* __p_next_node__ = (void*)(__n__)->xd_next; \
(__n__)->xd_next = (__n__)->xd_next->xd_next; \
__f__ ( __p_next_node__ ) ; \
} while(0)
#define XDS_slist_pop_front( __h__ , __f__ ) XDS_slist_erase_after( __h__ , __f__ )
#define XDS_slist_insert_after( __n__ , __p__ ) \
do { \
(__p__)->xd_next = (__n__)->xd_next; \
(__n__)->xd_next = (__p__); \
} while(0)
#define XDS_slist_push_front( __h__ , __p__ ) XDS_slist_insert_after( __h__ , __p__ )
#define XDS_slist_cleanup( __h__ , __f__ ) \
do { \
void* __p_first_node__ ; \
while( 1 ) \
{ \
XDS_slist_pop_front( __h__ , __p_first_node__ = ); \
if( (__h__) == __p_first_node__ ) break; \
__f__ ( __p_first_node__ ); \
} \
} while(0)
#define XDS_slist_for_each( __h__ , __n__ ) \
for( (__n__) = (__h__)->xd_next; (__h__) != (__n__); (__n__) = (__n__)->xd_next )
struct testList
{
struct testList * xd_next;
int xxTmmd;
};
void foobar()
{
int i;
struct testList l , *p;
XDS_slist_init( &l );
for( i = 0; i < 10; ++i )
{
if( NULL == ( p = malloc( sizeof( *p ) ) ) )
exit(2);
p->xxTmmd = i;
XDS_slist_push_front( &l , p );
}
XDS_slist_for_each( &l , p )
printf( "%d --> " , p->xxTmmd );
printf( "NULL\n" );
p = l.xd_next->xd_next;
XDS_slist_erase_after( p , free );
XDS_slist_for_each( &l , p )
printf( "%d --> " , p->xxTmmd );
printf( "NULL\n" );
XDS_slist_cleanup( &l , free );
}
int main()
{
foobar();
}
chenzhichao2008
2006-11-04
打赏
举报
回复
你是要实现模板吧
agaric
2006-11-03
打赏
举报
回复
... 顶多用指针来装箱拆箱吧,反正不爽.
C 语言版的
stl
简单
实现
一个通用的
C语言
编写的类似
STL
功能的集合库,
实现
比较简单,通用性比较强
stl
模板库的
c语言
实现
libc
stl
-2.3.0,用
c语言
实现
的c++ 模板库,包含map、tree、list、vector等的
实现
。
c语言
的
stl
标准模板库
c语言
stl
标准模板库 网页
c语言
stl
标准模板库 网页
C语言
版
STL
C语言
版本的
STL
(libc
stl
)源代码,支持跨平台的编译和使用。
C语言
版的
STL
,包含set,list,map等基本数据结构和算法.zip
C语言
版的
STL
,包含set,list,map等基本数据结构和算法.zip
C语言
70,023
社区成员
243,263
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章