VC & GCC(一)

 

VC8.0 & gcc version 3.4.2 (mingw-special)

// 标准的兼容性相关

// 模板特化相关
//VC8
 template<bool>struct VC8{};
 template<>struct VC8<false>{};

 VC8<true> vc8_0;
 VC8<false> vc8_1;
//OK

//GCC
 template<bool>struct GCC{};
 template<>struct GCC<false>{};
//LOST, Try Like This
 template<typanem gcc_only, bool>struct GCC{};
 template<typename gcc_only>struct GCC<gcc_only, false>{};
 GCC<void, true> gcc_0;
 GCC<void, false> gcc_1;
//OK
//小结:不知道是不是我这个gcc不是新版本,有这样的不支持单参特化推导的问题个人以为非常诧异...
//不管怎么说,这个问题影响不是很大,稍微有些麻烦而以,暂时还没有发现什么语意方面的误差
//话说回来, 我看GCC给的错误提示是 template<> 中 '>' 无法匹配, 难道就不知道 template<> 是标准的
//模板声明啊...


//名称空间定义域相关
//VC8
 namespace vc_space{template<typename T> struct VC8;}
 template<>struct vc_space::VC8<int>{};
//OK

//GCC
 namespace gcc_space{template<typename T>struct GCC;}
 template<>struct gcc_space::GCC<int>{};
//LOST, Try Like This
 namespace gcc_space{template<typename T>struct GCC;template<>struct GCC<int>{};}
 //或者这样
 namespace gcc_space{template<typename T>struct GCC;}
 //..other path
 namespace gcc_space{ template<>struct GCC<int>{}; }
//OK

//看起来像是 GCC 不支持外层空间下的类的定义。PS: VC8也不支持跨子层定义
//VC8 也不支持的一种情况
namespace vc_space{
namespace s1{template<typename> struct VC;}
namespace s2{template<> ::vc_space::s1::VC<int>{};}
//LOST
//非模板的情况还没有尝试过.
//小结:还是感觉VC要方便些, 而且某些情况下, VC的实现,和GCC的替代实现可能导致语意上的不一致性
//比如以下:
namespace vc_space{template<typename T> struct VC8;}
#define  VC_CLASS(_Ty) template<>struct vc_space::VC8<_Ty>{}

namespace gcc_space{template<typename T> struct GCC;}
#define  GCC_CLASS(_Ty) namespace gcc_space{ template<>struct GCC<_Ty>{}; }

//细心的朋友也许已经注意到
VC_CLASS(int) vc_class;  //OK
GCC_CLASS(int) gcc_class; //LOST

 

// Dev-C++ 的STL 库...
我VC中用STL一般喜欢这么用:
std::list<some_type, some_allocator<void> >;
然后让list自己去推导他需要的 allocator 类型, 省得以后我修改前面那个some_type的时候还需要额外维护一遍后面分配器的类型, 但是 Dev-C++里面的实现没有自动推导部分...
// DEV-C++ 附带提供的 STL
 template<typename _Tp, typename _Alloc = allocator<_Tp> >
    class list : protected _List_base<_Tp, _Alloc>
    {
      // concept requirements
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)

      typedef _List_base<_Tp, _Alloc>                   _Base;

    public:
      typedef _Tp                                        value_type;
 // 郁闷了, 被直接拿来使用, 自然就没法像在VC里面那么偷懒了...
      typedef typename _Alloc::pointer                   pointer;

// VC 附带提供的 STL
template<class _Ty,
 class _Alloc>
 class _List_val
  : public _List_ptr<_Ty, _Alloc>
 { // base class for list to hold allocator _Alval
public:
 // 这个地方 VC提供的实现 很聪明的自己重新推导了分配器类型..
 typedef typename _Alloc::template rebind<_Ty>::other _Alty;

//....
template<class _Ty,
 class _Ax = allocator<_Ty> >
 class list
  : public _List_val<_Ty, _Ax>
 { // bidirectional linked list
public:
 typedef _List_val<_Ty, _Ax> _Mybase;
 typedef typename _Mybase::_Alty _Alloc;
//......
 typedef typename _Alloc::size_type size_type;
 typedef typename _Alloc::difference_type _Dift;
 typedef _Dift difference_type;
 

//也许有的人对这个不以为然认为我偷懒, 但是当你面对如下的代码,你能够安分的那么费心费力吗?

 typedef std::list< allocator_base<0x004, block_size/0x004>, allocator_default<void> >  mem04_t;
 typedef std::list< allocator_base<0x008, block_size/0x008>, allocator_default<void> >  mem08_t;
 typedef std::list< allocator_base<0x010, block_size/0x010>, allocator_default<void> >  mem16_t;
 typedef std::list< allocator_base<0x020, block_size/0x020>, allocator_default<void> >  mem32_t;
 typedef std::list< allocator_base<0x040, block_size/0x040>, allocator_default<void> >  mem64_t;
 typedef std::list< allocator_base<0x080, block_size/0x080>, allocator_default<void> >  mem28_t;
 typedef std::list< allocator_base<0x100, block_size/0x100>, allocator_default<void> >  mem56_t;

不由得我想骂人了...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值