From 14d8c7b9ec632a1bba78df54c954f51a4c3f3e6d Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 7 May 2003 20:59:06 +0000 Subject: [PATCH] Initial re-commit after CVS disk crash [SVN r18349] --- include/boost/mpl/aux_/test/assert.hpp | 82 +++++++++++++++++++++++ include/boost/mpl/aux_/test/data.hpp | 44 ++++++++++++ include/boost/mpl/aux_/test/for_each.hpp | 60 +++++++++++++++++ include/boost/mpl/aux_/test/test_case.hpp | 40 +++++++++++ test/aux_/preprocessor/is_seq.cpp | 42 ++++++++++++ test/aux_/preprocessor/token_equal.cpp | 45 +++++++++++++ test/aux_/test/test_case.cpp | 42 ++++++++++++ 7 files changed, 355 insertions(+) create mode 100644 include/boost/mpl/aux_/test/assert.hpp create mode 100644 include/boost/mpl/aux_/test/data.hpp create mode 100644 include/boost/mpl/aux_/test/for_each.hpp create mode 100644 include/boost/mpl/aux_/test/test_case.hpp create mode 100644 test/aux_/preprocessor/is_seq.cpp create mode 100644 test/aux_/preprocessor/token_equal.cpp create mode 100644 test/aux_/test/test_case.cpp diff --git a/include/boost/mpl/aux_/test/assert.hpp b/include/boost/mpl/aux_/test/assert.hpp new file mode 100644 index 0000000..d790847 --- /dev/null +++ b/include/boost/mpl/aux_/test/assert.hpp @@ -0,0 +1,82 @@ + +#ifndef BOOST_MPL_AUX_TEST_ASSERT_HPP_INCLUDED +#define BOOST_MPL_AUX_TEST_ASSERT_HPP_INCLUDED + +// + file: boost/mpl/aux_/test/assert.hpp +// + last modified: 04/may/03 + +// Copyright (c) 2002-03 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/mpl/aux_/config/ctps.hpp" +#include "boost/mpl/aux_/config/msvc.hpp" +#include "boost/mpl/aux_/config/workaround.hpp" + +#include "boost/static_assert.hpp" + +#include "boost/preprocessor/tuple/rem.hpp" +#include "boost/preprocessor/control/expr_if.hpp" +#include "boost/preprocessor/logical/not.hpp" + +#define CTT_assert( expr ) BOOST_STATIC_ASSERT( expr ) +#define CTT_assert_equal(arity, tuple) assert_equal< BOOST_PP_TUPLE_REM(arity)tuple >::type() +#define CTT_assert_not_equal(arity, tuple) assert_not_equal< BOOST_PP_TUPLE_REM(arity)tuple >() +#define CTT_assert_same(arity, tuple) assert_same< BOOST_PP_TUPLE_REM(arity)tuple >() +#define CTT_assert_not_same(arity, tuple) assert_not_same< BOOST_PP_TUPLE_REM(arity)tuple >() + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) +# define AUX_ASSERT_DEF( param_type, suffix, test_equality ) \ +template< param_type x, param_type y > struct assert_##suffix \ +BOOST_PP_EXPR_IF( BOOST_PP_NOT(test_equality), {} ); \ +template< param_type x > struct assert_##suffix \ +BOOST_PP_EXPR_IF( test_equality, {} ); \ +/**/ +#elif BOOST_WORKAROUND(BOOST_MSVC, <= 1300) +# define AUX_ASSERT_DEF( param_type, suffix, test_equality ) \ +template< param_type x > struct assert_##suffix##_impl \ +{ \ + template< param_type y > struct result_; \ + template<> struct result_ \ + { BOOST_PP_EXPR_IF( BOOST_PP_NOT(test_equality), private: virtual ~result_() = 0; ) }; \ + template< param_type y > struct result_ \ + { BOOST_PP_EXPR_IF( test_equality, private: virtual ~result_() = 0; ) }; \ +}; \ +\ +template< param_type x, param_type y > struct assert_##suffix \ + : assert_##suffix##_impl::template result_ {}; \ +/**/ +#else +# define AUX_ASSERT_DEF( param_type, suffix, test_equality ) \ +template< param_type x > struct assert_##suffix##_impl \ +{ \ + template< param_type y > struct result_ \ + BOOST_PP_EXPR_IF( BOOST_PP_NOT(test_equality), {} ); \ +}; \ +template< param_type x > struct assert_##suffix##_impl::result_ \ +BOOST_PP_EXPR_IF( test_equality, {} ); \ +\ +template< param_type x, param_type y > struct assert_##suffix \ + : assert_##suffix##_impl::template result_ {}; \ +/**/ +#endif + +namespace { +AUX_ASSERT_DEF(long, equal, 1) +AUX_ASSERT_DEF(long, not_equal, 0) +AUX_ASSERT_DEF(typename, same, 1) +AUX_ASSERT_DEF(typename, not_same, 0) +} + +#undef AUX_ASSERT_DEF + +#endif // BOOST_MPL_AUX_TEST_ASSERT_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/test/data.hpp b/include/boost/mpl/aux_/test/data.hpp new file mode 100644 index 0000000..fafc616 --- /dev/null +++ b/include/boost/mpl/aux_/test/data.hpp @@ -0,0 +1,44 @@ + +#ifndef BOOST_MPL_AUX_TEST_DATA_HPP_INCLUDED +#define BOOST_MPL_AUX_TEST_DATA_HPP_INCLUDED + +// + file: boost/mpl/aux_/test/data.hpp +// + last modified: 04/may/03 + +// Copyright (c) 2002-03 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/noncopyable.hpp" + +struct UDT {}; +struct incomplete; +class abstract { virtual ~abstract() = 0; }; +using boost::noncopyable; + +// to do: add function types for compilers that are able to handle them +// (T ())(T (int))(void (T))(T (T)) +// (T[10])(T const[10])(T volatile[10])(T const volatile[10]) +// (T (*)())(T (* const)())(T (* volatile)())(T (* const volatile)()) +// (T (*)(int))(void (*)(T))(T (*)(T)) + +#define CTT_basic_modifiers( T ) \ + (T const)(T volatile)(T const volatile) \ + (T&)(T const&)(T volatile&)(T const volatile&) \ + (T*)(T const*)(T volatile*)(T const volatile*) \ +/**/ + +#define CTT_basic_types() \ + (bool)(char)(int)(UDT)(incomplete)(noncopyable)(abstract) \ +/**/ + +#endif // BOOST_MPL_AUX_TEST_DATA_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/test/for_each.hpp b/include/boost/mpl/aux_/test/for_each.hpp new file mode 100644 index 0000000..ea080d7 --- /dev/null +++ b/include/boost/mpl/aux_/test/for_each.hpp @@ -0,0 +1,60 @@ + +#ifndef BOOST_MPL_AUX_TEST_FOR_EACH_HPP_INCLUDED +#define BOOST_MPL_AUX_TEST_FOR_EACH_HPP_INCLUDED + +// + file: boost/mpl/aux_/test/for_each.hpp +// + last modified: 04/may/03 + +// Copyright (c) 2002-03 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/mpl/aux_/preprocessor/is_seq.hpp" + +#include "boost/preprocessor/seq/for_each_i.hpp" +#include "boost/preprocessor/seq/transform.hpp" +#include "boost/preprocessor/seq/enum.hpp" +#include "boost/preprocessor/tuple/elem.hpp" +#include "boost/preprocessor/control/expr_if.hpp" +#include "boost/preprocessor/cat.hpp" + +#define CTT_AUX_IS_PLACEHOLDER_1 (1) + +#define CTT_AUX_IS_PLACEHOLDER(x) \ + BOOST_MPL_PP_IS_SEQ( BOOST_PP_CAT(CTT_AUX_IS_PLACEHOLDER, x) ) \ +/**/ + +#define CTT_AUX_PARAM_OR_T( unused, T, param ) \ + BOOST_PP_TUPLE_ELEM( 2, CTT_AUX_IS_PLACEHOLDER(param), (param, T) ) \ +/**/ + +#define CTT_AUX_REPLACE_PLACEHOLDER( params_seq, T ) \ + BOOST_PP_SEQ_ENUM( \ + BOOST_PP_SEQ_TRANSFORM( CTT_AUX_PARAM_OR_T, T, params_seq ) \ + ) \ +/**/ + +#define CTT_AUX_INVOKE_TEST( unused, test_params_pair, i, T ) \ + BOOST_PP_EXPR_IF(i, ;) \ + BOOST_PP_TUPLE_ELEM(2, 0, test_params_pair)< \ + CTT_AUX_REPLACE_PLACEHOLDER( \ + BOOST_PP_TUPLE_ELEM(2, 1, test_params_pair) \ + , T \ + ) \ + >() \ +/**/ + +#define CTT_for_each( seq, test, params_seq ) \ + BOOST_PP_SEQ_FOR_EACH_I( CTT_AUX_INVOKE_TEST, (test, params_seq), seq ) \ +/**/ + +#endif // BOOST_MPL_AUX_TEST_FOR_EACH_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/test/test_case.hpp b/include/boost/mpl/aux_/test/test_case.hpp new file mode 100644 index 0000000..08adee0 --- /dev/null +++ b/include/boost/mpl/aux_/test/test_case.hpp @@ -0,0 +1,40 @@ + +#ifndef BOOST_MPL_AUX_TEST_TEST_CASE_HPP_INCLUDED +#define BOOST_MPL_AUX_TEST_TEST_CASE_HPP_INCLUDED + +// + file: boost/mpl/aux_/test/test_case.hpp +// + last modified: 04/may/03 + +// Copyright (c) 2002-03 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/preprocessor/comma_if.hpp" +#include "boost/preprocessor/seq/for_each_i.hpp" +#include "boost/preprocessor/seq/enum.hpp" + +#define CTT_AUX_PARAM_DEF(unused, prefix, i, elem) \ + BOOST_PP_COMMA_IF(i) prefix elem \ +/**/ + +#define CTT_test_case( name, params_seq ) \ +template< \ + BOOST_PP_SEQ_FOR_EACH_I( CTT_AUX_PARAM_DEF, typename, params_seq ) \ + > \ +void name() \ +/**/ + +#define CTT_test( test, params_seq ) \ + test< BOOST_PP_SEQ_ENUM(params_seq) >() \ +/**/ + +#endif // BOOST_MPL_AUX_TEST_TEST_CASE_HPP_INCLUDED diff --git a/test/aux_/preprocessor/is_seq.cpp b/test/aux_/preprocessor/is_seq.cpp new file mode 100644 index 0000000..222954d --- /dev/null +++ b/test/aux_/preprocessor/is_seq.cpp @@ -0,0 +1,42 @@ + +// + file: libs/mpl/test/aux_/is_seq.cpp +// + last modified: 03/may/03 + +// Copyright (c) 2003 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/mpl/aux_/preprocessor/is_seq.hpp" + +#include "boost/preprocessor/logical/not.hpp" +#include "boost/preprocessor/debug/assert.hpp" + +#define AUX_ASSERT_IS_SEQ( seq ) \ + BOOST_PP_ASSERT( BOOST_MPL_PP_IS_SEQ(seq) ) \ +/**/ + +#define AUX_ASSERT_IS_NOT_SEQ( seq ) \ + BOOST_PP_ASSERT( BOOST_PP_NOT( BOOST_MPL_PP_IS_SEQ(seq) ) ) \ +/**/ + +#define SEQ (a)(b)(c) + +int main() +{ + AUX_ASSERT_IS_NOT_SEQ( a ) + AUX_ASSERT_IS_SEQ( (a) ) + AUX_ASSERT_IS_SEQ( (a)(b) ) + AUX_ASSERT_IS_SEQ( (a)(b)(c) ) + AUX_ASSERT_IS_SEQ( SEQ ) + + return 0; +} diff --git a/test/aux_/preprocessor/token_equal.cpp b/test/aux_/preprocessor/token_equal.cpp new file mode 100644 index 0000000..b209625 --- /dev/null +++ b/test/aux_/preprocessor/token_equal.cpp @@ -0,0 +1,45 @@ + +// + file: libs/mpl/test/aux_/token_eqaul.cpp +// + last modified: 03/may/03 + +// Copyright (c) 2003 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/mpl/aux_/preprocessor/token_equal.hpp" + +#include "boost/preprocessor/logical/not.hpp" +#include "boost/preprocessor/debug/assert.hpp" + +#define AUX_ASSERT_EQUAL(x, y) \ + BOOST_PP_ASSERT( BOOST_MPL_PP_TOKEN_EQUAL(x, y) ) \ +/**/ + +#define AUX_ASSERT_NOT_EQUAL(x, y) \ + BOOST_PP_ASSERT( BOOST_PP_NOT( BOOST_MPL_PP_TOKEN_EQUAL(x, y) ) ) \ +/**/ + +int main() +{ + #define BOOST_MPL_PP_TOKEN_EQUAL_apple(x) x + #define BOOST_MPL_PP_TOKEN_EQUAL_orange(x) x + + AUX_ASSERT_NOT_EQUAL( apple, abc ) + AUX_ASSERT_NOT_EQUAL( abc, apple ) + AUX_ASSERT_NOT_EQUAL( apple, orange ) + AUX_ASSERT_NOT_EQUAL( orange, apple ) + + AUX_ASSERT_EQUAL( apple, apple ) + AUX_ASSERT_EQUAL( orange, orange ) + + return 0; +} diff --git a/test/aux_/test/test_case.cpp b/test/aux_/test/test_case.cpp new file mode 100644 index 0000000..4722044 --- /dev/null +++ b/test/aux_/test/test_case.cpp @@ -0,0 +1,42 @@ + +// + file: libs/mpl/aux_/test/test_case.cpp +// + last modified: 03/may/03 + +// Copyright (c) 2002-03 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +// +// See http://www.boost.org/libs/mpl for documentation. + +#include "boost/mpl/aux_/test.hpp" + +CTT_test_case( false_positives, (S)(T) ) +{ + CTT_assert_same( 2, (S, char) ); + CTT_assert_not_same( 2, (S, bool) ); + //T t; +} + +CTT_test_case( empty_set, (T) ) + { + CTT_for_each( + (T)(T const) + , false_positives + , (char)(_1) + ); + } + +int main() +{ + CTT_test( empty_set, (bool) ); + CTT_for_each( (int)(long), empty_set, (_1) ); + + return 0; +}