- 浏览: 211428 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
zhuchao_ko:
有用的废话。。。
架构与产品 -
450029462:
java学好了 c++其实也不难,就是 宏多点 内存控制多点 ...
从java转向C\c++开发要学会些什么 -
ldlzagg:
...
启示2013 -
raojl:
书是买了, 一直没时间捣鼓!
我发现开始喜欢Python了 -
raojl:
回过头看了看也不全然对啊,呵呵!
IT行业发展‘VIA’模式探讨
1、版本编译控制(比如多项目)
2、编译校验
3、static_cast
----------------------------------------------------------
// static_check.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> using namespace std; namespace Loki { //////////////////////////////////////////////////////////////////////////////// // Helper structure for the STATIC_CHECK macro //////////////////////////////////////////////////////////////////////////////// template<int> struct CompileTimeError; template<> struct CompileTimeError<true> {}; } //////////////////////////////////////////////////////////////////////////////// // macro STATIC_CHECK // Invocation: STATIC_CHECK(expr, id) // where: // expr is a compile-time integral or pointer expression // id is a C++ identifier that does not need to be defined // If expr is zero, id will appear in a compile-time error message. //////////////////////////////////////////////////////////////////////////////// #define STATIC_CHECK(expr, msg) \ { Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; } int _tmain(int argc, _TCHAR* argv[]) { STATIC_CHECK((sizeof(int) == 4 && sizeof(long) == 4), 32bit); STATIC_CHECK((sizeof(int) != sizeof(long)), 64bit); return 0; }
////////////////////////////////////////////////////////////////////////////////
// The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author or Addison-Welsey Longman make no representations about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// // Last update: November 22, 2001 #ifndef TYPEMANIP_INC_ #define TYPEMANIP_INC_ namespace Loki { //////////////////////////////////////////////////////////////////////////////// // class template Int2Type // Converts each integral constant into a unique type // Invocation: Int2Type<v> where v is a compile-time constant integral // Defines 'value', an enum that evaluates to v //////////////////////////////////////////////////////////////////////////////// template <int v> struct Int2Type { enum { value = v }; }; //////////////////////////////////////////////////////////////////////////////// // class template Type2Type // Converts each type into a unique, insipid type // Invocation Type2Type<T> where T is a type // Defines the type OriginalType which maps back to T //////////////////////////////////////////////////////////////////////////////// template <typename T> struct Type2Type { typedef T OriginalType; }; //////////////////////////////////////////////////////////////////////////////// // class template Select // Selects one of two types based upon a boolean constant // Invocation: Select<flag, T, U>::Result // where: // flag is a compile-time boolean constant // T and U are types // Result evaluates to T if flag is true, and to U otherwise. //////////////////////////////////////////////////////////////////////////////// template <bool flag, typename T, typename U> struct Select { typedef T Result; }; template <typename T, typename U> struct Select<false, T, U> { typedef U Result; }; //////////////////////////////////////////////////////////////////////////////// // class template IsSameType // Return true iff two given types are the same // Invocation: SameType<T, U>::value // where: // T and U are types // Result evaluates to true iff U == T (types equal) //////////////////////////////////////////////////////////////////////////////// template <typename T, typename U> struct IsSameType { enum { value = false }; }; template <typename T> struct IsSameType<T,T> { enum { value = true }; }; //////////////////////////////////////////////////////////////////////////////// // Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big) //////////////////////////////////////////////////////////////////////////////// namespace Private { template <class T, class U> struct ConversionHelper { typedef char Small; struct Big { char dummy[2]; }; static Big Test(...); static Small Test(U); static T MakeT(); }; } //////////////////////////////////////////////////////////////////////////////// // class template Conversion // Figures out the conversion relationships between two types // Invocations (T and U are types): // a) Conversion<T, U>::exists // returns (at compile time) true if there is an implicit conversion from T // to U (example: Derived to Base) // b) Conversion<T, U>::exists2Way // returns (at compile time) true if there are both conversions from T // to U and from U to T (example: int to char and back) // c) Conversion<T, U>::sameType // returns (at compile time) true if T and U represent the same type // // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// template <class T, class U> struct Conversion { typedef Private::ConversionHelper<T, U> H; #ifndef __MWERKS__ enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) }; #else enum { exists = false }; #endif enum { exists2Way = exists && Conversion<U, T>::exists }; enum { sameType = false }; }; template <class T> struct Conversion<T, T> { enum { exists = 1, exists2Way = 1, sameType = 1 }; }; template <class T> struct Conversion<void, T> { enum { exists = 0, exists2Way = 0, sameType = 0 }; }; template <class T> struct Conversion<T, void> { enum { exists = 0, exists2Way = 0, sameType = 0 }; }; template <> struct Conversion<void, void> { public: enum { exists = 1, exists2Way = 1, sameType = 1 }; }; //////////////////////////////////////////////////////////////////////////////// // class template SuperSubclass // Invocation: SuperSubclass<B, D>::value where B and D are types. // Returns true if B is a public base of D, or if B and D are aliases of the // same type. // // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// template <class T, class U> struct SuperSubclass { enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists && !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) }; }; //////////////////////////////////////////////////////////////////////////////// // class template SuperSubclassStrict // Invocation: SuperSubclassStrict<B, D>::value where B and D are types. // Returns true if B is a public base of D. // // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// template<class T,class U> struct SuperSubclassStrict { enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists && !::Loki::Conversion<const volatile T*, const volatile void*>::sameType && !::Loki::Conversion<const volatile T*, const volatile U*>::sameType) }; }; } // namespace Loki //////////////////////////////////////////////////////////////////////////////// // macro SUPERSUBCLASS // Invocation: SUPERSUBCLASS(B, D) where B and D are types. // Returns true if B is a public base of D, or if B and D are aliases of the // same type. // // Caveat: might not work if T and U are in a private inheritance hierarchy. // Deprecated: Use SuperSubclass class template instead. //////////////////////////////////////////////////////////////////////////////// #define SUPERSUBCLASS(T, U) \ ::Loki::SuperSubclass<T,U>::value //////////////////////////////////////////////////////////////////////////////// // macro SUPERSUBCLASS_STRICT // Invocation: SUPERSUBCLASS(B, D) where B and D are types. // Returns true if B is a public base of D. // // Caveat: might not work if T and U are in a private inheritance hierarchy. // Deprecated: Use SuperSubclassStrict class template instead. //////////////////////////////////////////////////////////////////////////////// #define SUPERSUBCLASS_STRICT(T, U) \ ::Loki::SuperSubclassStrict<T,U>::value //////////////////////////////////////////////////////////////////////////////// // Change log: // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! // November 22, 2001: minor change to support porting to boost // November 22, 2001: fixed bug in Conversion<void, T> // (credit due to Brad Town) // November 23, 2001: (well it's 12:01 am) fixed bug in SUPERSUBCLASS - added // the volatile qualifier to be 100% politically correct // September 16, 2002: Changed "const volatile" to "const volatile *", to enable // conversion to succeed. Done earlier by MKH. // Added SuperSubclass and SuperSubclassStrict templates. The corresponding // macros are deprecated. // Added extra parenthesis in sizeof in Conversion, to disambiguate function // call from function declaration. T.S. //////////////////////////////////////////////////////////////////////////////// #endif // TYPEMANIP_INC_
发表评论
-
服务端口快扫shell
2014-08-25 11:50 703#set -x var_start=8000 arra ... -
远程批量部署
2014-07-29 11:50 611#!/usr/bin/expect -- if ... -
linux 下建立异步链接
2014-05-07 11:59 556int32_t SockEndPoint::connect_ ... -
atomic笔记
2013-12-11 11:43 373inline void ice_atomic_set(ic ... -
求最大公共子串
2013-07-15 11:21 707#include <stdio.h> #inc ... -
日志记录
2013-01-14 09:25 729[root@localhost Capserver]# ... -
c开发笔记
2012-02-03 09:36 6901、就是有大量的输入参数或输出参数需要一次性交换时,可以考虑定 ... -
GCC注意笔记
2011-02-22 18:38 715大多数程序和库在编译 ... -
邻接表实现状态图【大家帮忙看看问题】
2010-06-26 18:15 899StatusGrap.cpp // StatusGraph ... -
gsoap编写webservice应用
2010-06-01 15:02 2143The gSOAP tools minimize applic ... -
setsockopt 笔记
2010-04-22 15:12 8001、TCP_NODELAY是唯一使用IPPROTO_TCP层的 ... -
随录-增量记录
2010-02-25 10:41 658程序开发,对于日志的记录需要主要以下几个问题。 1、多线程或 ... -
快速入门sqlite内存数据库,用sqlite构建一日志工具
2009-12-25 11:28 3709今天上午无意在搜索的时候发现很多应用程序用了sqllite,o ... -
dos脚本+ftp实现快速升级
2009-12-25 09:52 1474cd \ ;写ftpget.src文件,存储ftp命令。该文件 ... -
花三分钟看看这个文档
2009-11-30 19:14 786linux 命令精简 Unix/Linux Command ... -
推荐一款xml分析微型库tinyxml
2009-08-22 08:16 1288tinyxml,至所以叫tin,就是短小精悍。搭配前面讲的gs ... -
用gsoap编写webservice客户端接口dll的方法案例
2009-08-22 07:55 29051)使用手册:见http://gsoap2.source ... -
命令随写
2009-08-13 16:22 723ocrale启动监听:lsnrctl start 启动服务:o ... -
LUA 分析文件
2009-06-02 14:07 1121BUFSIZE = 2^13 -- 8K ... -
避免对指针和数字类型重载
2009-05-22 14:17 791条款25: 避免对指针和数字类型重载 快速抢答: ...
评论