[complement-svn] SF.net SVN: complement: [1675] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-08-06 07:01:17
|
Revision: 1675 http://complement.svn.sourceforge.net/complement/?rev=1675&view=rev Author: complement Date: 2007-08-06 00:01:16 -0700 (Mon, 06 Aug 2007) Log Message: ----------- more traits; established unit tests for type_traits workaround Modified Paths: -------------- trunk/complement/explore/include/misc/type_traits.h Added Paths: ----------- trunk/complement/explore/lib/misc/ut/ trunk/complement/explore/lib/misc/ut/Makefile trunk/complement/explore/lib/misc/ut/Makefile.inc trunk/complement/explore/lib/misc/ut/misc_test.cc trunk/complement/explore/lib/misc/ut/misc_test.h trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/misc_test_suite.h trunk/complement/explore/lib/misc/ut/unit_test.cc Modified: trunk/complement/explore/include/misc/type_traits.h =================================================================== --- trunk/complement/explore/include/misc/type_traits.h 2007-08-06 06:57:59 UTC (rev 1674) +++ trunk/complement/explore/include/misc/type_traits.h 2007-08-06 07:01:16 UTC (rev 1675) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/03 08:59:36 ptr> +// -*- C++ -*- Time-stamp: <07/08/06 10:30:28 ptr> /* * Copyright (c) 2007 @@ -15,22 +15,69 @@ #include <config/feature.h> #endif -#if !defined(STLPORT) /* || (_STLPORT_VERSION < 50200) */ +#if 1 /* !defined(STLPORT) */ /* || (_STLPORT_VERSION < 50200) */ // libstdc++ v3, timestamp 20050519 (3.4.4) has __type_traits, // libstdc++ v3, timestamp 20060306 (3.4.6) has __type_traits, // while libstdc++ v3, 20050921 (4.0.2) not; use libstdc++ instead -# if !defined(__GLIBCXX__) || (defined(__GNUC__) && (__GNUC__ < 4)) +# if 1 /* !defined(__GLIBCXX__) || (defined(__GNUC__) && (__GNUC__ < 4)) */ namespace std { namespace tr1 { +namespace detail { + +struct __select_types +{ + typedef char __t1; + struct __t2 + { + char __two[2]; + }; +}; + +template <class _Tp> +struct __instance : + public __select_types +{ + private: + template <class _Up> + static __t1 __test(_Up(*)[1]); + + template <class> + static __t2 __test(...); + + public: + static const bool __value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class T> +struct __uoc_aux : // union or class + public __select_types +{ + private: + template <class _Up> + static __t1 __test( int _Up::* ); + + template <class> + static __t2 __test(...); + + public: + static const bool __value = sizeof(__test<T>(0)) == 1; +}; + +template <class T> +class __empty +{ }; + +} // namespace detail + template <class _Tp, _Tp __v> struct integral_constant { static const _Tp value = __v; - // enum { value = __v }; + // enum { value = __v }; ? typedef _Tp value_type; typedef integral_constant<_Tp, __v> type; @@ -39,6 +86,15 @@ typedef integral_constant<bool, true> true_type; typedef integral_constant<bool, false> false_type; +namespace detail { + +template<typename _Tp> +struct __is_union_or_class : + public integral_constant<bool, __uoc_aux<_Tp>::__value> +{ }; + +} // namespace detail + #define __SPEC_(C,T,B) \ template <> \ struct C<T> : \ @@ -75,6 +131,8 @@ __SPEC_2(C,T volatile,B); \ __SPEC_2(C,T const volatile,B) +// [4.5.1] primary type categories: + template <class _Tp> struct is_void : public false_type @@ -111,21 +169,6 @@ __SPEC_FULL(is_floating_point,long double,true); template <class _Tp> -struct is_arithmetic : - public integral_constant<bool, (is_integral<_Tp>::value || is_floating_point<_Tp>::value)> -{ }; - -template <class _Tp> -struct is_fundamental : - public integral_constant<bool, (is_arithmetic<_Tp>::value || is_void<_Tp>::value)> -{ }; - -template <class _Tp> -struct is_compound : - public integral_constant<bool, !is_fundamental<_Tp>::value> -{ }; - -template <class _Tp> struct is_array : public false_type { }; @@ -159,9 +202,9 @@ template <class _Tp> struct is_function : - public integral_constant<bool, !(/* __in_array<_Tp>::__value - || __is_union_or_class<_Tp>::value - || */ is_reference<_Tp>::value + public integral_constant<bool, !(detail::__instance<_Tp>::__value + || detail::__is_union_or_class<_Tp>::value + || is_reference<_Tp>::value || is_void<_Tp>::value)> { }; @@ -224,7 +267,21 @@ public integral_constant<bool, (is_member_object_pointer<_Tp>::value || is_member_function_pointer<_Tp>::value)> { }; +// 4.5.2 composite type categories + template <class _Tp> +struct is_arithmetic : + public integral_constant<bool, (is_integral<_Tp>::value || is_floating_point<_Tp>::value)> +{ }; + +template <class _Tp> +struct is_fundamental : + public integral_constant<bool, (is_arithmetic<_Tp>::value || is_void<_Tp>::value)> +{ }; + +// [4.5.1] primary type categories (continued): + +template <class _Tp> struct is_enum : public integral_constant<bool, !(is_fundamental<_Tp>::value || is_array<_Tp>::value @@ -232,13 +289,28 @@ || is_reference<_Tp>::value || is_member_pointer<_Tp>::value || is_function<_Tp>::value - /* || __is_union_or_class<_Tp>::value */) > + || detail::__is_union_or_class<_Tp>::value) > { }; +template <class T> +struct is_union +{ }; + +template <class T> +struct is_class +{ }; + +// is_function (above) + +// 4.5.2 composite type categories (continued) + +// is_arithmetic (above) +// is_fundamental (above) + template <class _Tp> struct is_object : - public integral_constant<bool, !(is_function<_Tp>::value /* || is_reference<_Tp>::value - || is_void<_Tp>::value */ )> + public integral_constant<bool, !(is_function<_Tp>::value || is_reference<_Tp>::value + || is_void<_Tp>::value)> { }; template <class _Tp> @@ -250,22 +322,13 @@ { }; template <class _Tp> -struct remove_all_extents -{ - typedef _Tp type; -}; +struct is_compound : + public integral_constant<bool, !is_fundamental<_Tp>::value> +{ }; -template <class _Tp, std::size_t _Size> -struct remove_all_extents<_Tp[_Size]> -{ - typedef typename remove_all_extents<_Tp>::type type; -}; +// is_member_pointer -template<typename _Tp> -struct remove_all_extents<_Tp[]> -{ - typedef typename remove_all_extents<_Tp>::type type; -}; +// 4.5.3 type properties: template <class _Tp> struct is_const : @@ -287,12 +350,62 @@ public true_type { }; + +// 4.7.3 array modifications: + template <class _Tp> +struct remove_extent +{ + typedef _Tp type; +}; + +template <class _Tp, std::size_t _Sz> +struct remove_extent<_Tp[_Sz]> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_extent<_Tp[]> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_all_extents +{ + typedef _Tp type; +}; + +template <class _Tp, std::size_t _Size> +struct remove_all_extents<_Tp[_Size]> +{ + typedef typename remove_all_extents<_Tp>::type type; +}; + +template<typename _Tp> +struct remove_all_extents<_Tp[]> +{ + typedef typename remove_all_extents<_Tp>::type type; +}; + +// 4.5.3 type properties (continued): + +template <class _Tp> struct is_pod : public integral_constant<bool, (is_void<_Tp>::value || is_scalar<typename remove_all_extents<_Tp>::type>::value)> { }; +template<typename _Tp> +struct is_empty + : public integral_constant<bool, (detail::__is_union_or_class<_Tp>::__value + && (sizeof(detail::__empty<_Tp>) == sizeof(_Tp)))> +{ }; + +// is_polimorphic +// is_abstract + template <class _Tp> struct has_trivial_constructor : public integral_constant<bool, is_pod<_Tp>::value> @@ -355,6 +468,145 @@ __SPEC_FULL(is_unsigned,unsigned long,true); __SPEC_FULL(is_unsigned,unsigned long long,true); +// alignment_of +// rank +// extent + +// 4.6 type relations: + +template <class _Tp1, class _Tp2> +struct is_same : + public false_type +{ }; + +template <class _Tp> +struct is_same<_Tp, _Tp> : + public true_type +{ }; + +// is_base_of +// is_convertible + +// 4.7.1 const-volatile modifications + +template <class _Tp> +struct remove_const +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_const<_Tp const> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_volatile +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_volatile<_Tp volatile> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_cv +{ + typedef typename remove_const<typename remove_volatile<_Tp>::type>::type type; +}; + +template <class _Tp> +struct add_const +{ + typedef _Tp const type; +}; + +template <class _Tp> +struct add_volatile +{ + typedef _Tp volatile type; +}; + +template <class _Tp> +struct add_cv +{ + typedef typename add_const<typename add_volatile<_Tp>::type>::type type; +}; + +// 4.7.2 reference modifications: + +template <class _Tp> +struct remove_reference +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_reference<_Tp&> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct add_reference +{ + typedef _Tp& type; +}; + +template <class _Tp> +struct add_reference<_Tp&> +{ + typedef _Tp& type; +}; + +// 4.7.3 array modifications (see above) + +// 4.7.4 pointer modifications: + +template <class _Tp> +struct remove_pointer +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_pointer<_Tp *> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_pointer<_Tp * const> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_pointer<_Tp * volatile> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct remove_pointer<_Tp * const volatile> +{ + typedef _Tp type; +}; + +template <class _Tp> +struct add_pointer +{ + typedef typename remove_reference<_Tp>::type * type; +}; + +// 4.8 other transformations: + +// aligned_storage + #undef __SPEC_FULL #undef __SPEC_ #undef __SPEC_FULL1 Property changes on: trunk/complement/explore/lib/misc/ut ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/lib/misc/ut/Makefile =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile (rev 0) +++ trunk/complement/explore/lib/misc/ut/Makefile 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,60 @@ +# -*- Makefile -*- Time-stamp: <07/08/06 10:19:59 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + + +INCLUDES += -I$(SRCROOT)/include +DEFS += -D__FIT_EXAM + +LIBEXAM_DIR = ${CoMT_DIR}/lib/exam + +ifeq ($(OSNAME),linux) + +release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +endif + +endif + +ifeq ($(OSNAME),openbsd) + +release-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} + +dbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} + +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} +endif + +endif + +release-shared : LDLIBS = -lexam +dbg-shared : LDLIBS = -lexamg +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS = -lexamstlg +endif + +ifeq ($(OSNAME),freebsd) +release-shared : LDLIBS += -lthr +dbg-shared : LDLIBS += -lthr +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lthr +endif +endif + +ifeq ($(OSNAME),sunos) +release-shared : LDLIBS += -lrt +dbg-shared : LDLIBS += -lrt +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lrt +endif +endif + + Added: trunk/complement/explore/lib/misc/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile.inc (rev 0) +++ trunk/complement/explore/lib/misc/ut/Makefile.inc 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,5 @@ +# -*- makefile -*- Time-stamp: <07/07/16 22:12:31 ptr> + +PRGNAME = misc_ut +SRC_CC = unit_test.cc \ + misc_test.cc misc_test_suite.cc Added: trunk/complement/explore/lib/misc/ut/misc_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.cc (rev 0) +++ trunk/complement/explore/lib/misc/ut/misc_test.cc 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,62 @@ +// -*- C++ -*- Time-stamp: <07/08/06 10:26:25 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include "misc_test.h" + +#include <misc/type_traits.h> +#include <iostream> + +using namespace std; + +class MyType +{ + public: + + virtual int abstract() = 0; + + private: + int a; + int n; +}; + +class MyTypeOther +{ + public: + + private: + int a; + int n; +}; + +int f() +{ + return 0; +} + +template <class T> +static bool q( T v ) +{ + return std::tr1::detail::__instance<T>::__value; +} + +int EXAM_IMPL(misc_test::type_traits) +{ + EXAM_CHECK( std::tr1::detail::__instance<int []>::__value == true ); + EXAM_CHECK( std::tr1::detail::__instance<int *>::__value == true ); + EXAM_CHECK( std::tr1::detail::__instance<int&>::__value == false ); + EXAM_CHECK( std::tr1::detail::__instance<MyTypeOther>::__value == true ); + EXAM_CHECK( std::tr1::detail::__instance<int>::__value == true ); + EXAM_CHECK( std::tr1::detail::__instance<MyType>::__value == false ); + EXAM_CHECK( std::tr1::detail::__instance<int (*)()>::__value == true ); + EXAM_CHECK( std::tr1::detail::__instance<int (&)()>::__value == false ); + EXAM_CHECK( q(f) == true ); + + return EXAM_RESULT; +} Added: trunk/complement/explore/lib/misc/ut/misc_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.h (rev 0) +++ trunk/complement/explore/lib/misc/ut/misc_test.h 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,24 @@ +// -*- C++ -*- Time-stamp: <07/07/16 21:01:43 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __MISC_TEST_H +#define __MISC_TEST_H + +#define FIT_EXAM + +#include <exam/suite.h> + +class misc_test +{ + public: + int EXAM_DECL(type_traits); +}; + +#endif // __MISC_TEST_H Added: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc (rev 0) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,26 @@ +// -*- C++ -*- Time-stamp: <07/07/17 10:20:08 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include "misc_test_suite.h" +#include "misc_test.h" + +#include <config/feature.h> + +int EXAM_IMPL(misc_test_suite) +{ + exam::test_suite t( "libmisc? test" ); + misc_test test; + + exam::test_suite::test_case_type tc[3]; + + tc[0] = t.add( &misc_test::type_traits, test, "misc_test::type_traits" ); + + return t.girdle(); +}; Added: trunk/complement/explore/lib/misc/ut/misc_test_suite.h =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.h (rev 0) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.h 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,18 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:08:39 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __MISC_TEST_SUITE_H +#define __MISC_TEST_SUITE_H + +#include <exam/suite.h> + +int EXAM_DECL(misc_test_suite); + +#endif // __MISC_TEST_SUITE_H Added: trunk/complement/explore/lib/misc/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/unit_test.cc (rev 0) +++ trunk/complement/explore/lib/misc/ut/unit_test.cc 2007-08-06 07:01:16 UTC (rev 1675) @@ -0,0 +1,19 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:12:10 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include <exam/suite.h> +#include <config/feature.h> + +#include "misc_test_suite.h" + +int main( int, char ** ) +{ + return misc_test_suite(0); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |